-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Blocks rendering in Next.js (pages/mocked graphql calls) #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
2086b6f
chore: initialize nextjs project
ahuseyn 9fd82b3
chore: further project setup
ahuseyn a6fe2ba
feat: pull flatListToHierarchical from faust
ahuseyn 74b5fa5
feat: add BlockRenderer and DefaultBlock
ahuseyn 7181ef4
feat: add new blocks
ahuseyn 4b06ad9
feat: add more blocks
ahuseyn c013087
feat: add blocks index
ahuseyn a035b80
fix: add getInlineStyles for proper style handling
ahuseyn c514b39
fix: add data to default block
ahuseyn db21851
feat: add homepage and post data
ahuseyn f32d3ef
fix: autoPlay in CoreAudio
ahuseyn b7816d2
fix: update post data
ahuseyn 0cb34ff
feat: add Caption component
ahuseyn 512c11d
fix: add global style, fix mockRequest method
ahuseyn 5d80160
chore: add readme
ahuseyn f9f7982
fix: add title to index
ahuseyn d2e42e3
fix: add customParser to BlockRenderer
ahuseyn 7e0c1f2
fix: update post.json
ahuseyn b2ef8ac
fix: project structure in readme
ahuseyn 30ccc9a
Update examples/next/render-blocks-pages-router/README.md
ahuseyn a9a3b68
Update examples/next/render-blocks-pages-router/README.md
ahuseyn 7c2fed5
Update examples/next/render-blocks-pages-router/README.md
ahuseyn c205da6
feat: add nvmrc
ahuseyn ee3d42a
docs: add screenshot to the readme
ahuseyn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
|
||
| # dependencies | ||
| /node_modules | ||
| /.pnp | ||
| .pnp.* | ||
| .yarn/* | ||
| !.yarn/patches | ||
| !.yarn/plugins | ||
| !.yarn/releases | ||
| !.yarn/versions | ||
|
|
||
| # testing | ||
| /coverage | ||
|
|
||
| # next.js | ||
| /.next/ | ||
| /out/ | ||
|
|
||
| # production | ||
| /build | ||
|
|
||
| # misc | ||
| .DS_Store | ||
| *.pem | ||
|
|
||
| # debug | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| .pnpm-debug.log* | ||
|
|
||
| # env files (can opt-in for committing if needed) | ||
| .env* | ||
|
|
||
| # vercel | ||
| .vercel | ||
|
|
||
| # typescript | ||
| *.tsbuildinfo | ||
| next-env.d.ts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| lts/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| # Example: Rendering WordPress Blocks in Next.js | ||
|
|
||
| This example demonstrates rendering WordPress Blocks with JSX in a Next.js project. The example includes 16 block components across various categories. Example includes a utility to convert flat blocks data from GraphQL (GQL) response into the hierarchical data structure. Passing this data into BlockRenderer component generates the WordPress content by matching the appropriate blocks and using a default block when block implementation is missing. Default block is also customizable component. Example also gives an option to provide custom HTML parser to render HTML content. | ||
|
|
||
| ## Features | ||
|
|
||
| - 16 sample block components | ||
| - Custom HTML parser option | ||
| - Default block for fallback | ||
| - Custom default block option | ||
| - Utility to form inline CSS | ||
| - Utility to convert flat GQL data into hierarchical data | ||
| - GraphQL fragments for each block | ||
|
|
||
| ## Important notes | ||
|
|
||
| - This example does not require a working WordPress instance, it uses a fake request to get a prefetched GQL response | ||
| - If you have a working WordPress instance you can easily connect it to this example. For the details check the `pages/index.js` file. | ||
| - You will need to have [`wp-graphql-content-blocks`](https://github.com/wpengine/wp-graphql-content-blocks) and [`WPGraphQL`](https://wordpress.org/plugins/wp-graphql/) plugins installed if you want to connect it to a WordPress instance. | ||
|
|
||
| ## Project structure | ||
|
|
||
| ``` | ||
| / | ||
| ├── public/ | ||
| │ ├── post.json # Example GraphQL post data | ||
| ├── pages/ | ||
| │ ├── index.js # Home page to showcase all blocks | ||
| ├── components/ | ||
| │ ├── Caption.js # Component for figcaption and caption elements | ||
| │ ├── DefaultBlock.js # Default block to render if there's no corresponding block | ||
| │ ├── BlockRenderer.js # Component to render to render blocks | ||
| │ ├── blocks/ | ||
| │ │ ├── CoreAudio.js # Audio block component | ||
| │ │ ├── CoreButton.js # Button block component | ||
| │ │ └── ... # Other block components | ||
| ├── utils/ | ||
| │ ├── flatListToHierarchical.js # Convert GraphQL data into hierarchical | ||
| │ ├── getInlineStyles.js # Parse inline styles | ||
| ├── package.json # Project dependencies and scripts | ||
| ``` | ||
|
|
||
| ## Installation and Setup | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| 1. Node.js 18.18 or later | ||
| 2. npm or another package manager | ||
|
|
||
| ### Clone the repository | ||
|
|
||
| ```bash | ||
| git clone https://github.com/wpengine/hwptoolkit.git | ||
| cd examples/next/render-blocks-pages-router | ||
| ``` | ||
|
|
||
| ### Install dependencies | ||
|
|
||
| ```bash | ||
| npm install | ||
| ``` | ||
|
|
||
| ### Start the development server | ||
|
|
||
| ```bash | ||
| npm run dev | ||
| ``` | ||
ahuseyn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| http://localhost:3000/ should render the blocks as shown below. | ||
|
|
||
|  | ||
20 changes: 20 additions & 0 deletions
20
examples/next/render-blocks-pages-router/eslint.config.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { FlatCompat } from "@eslint/eslintrc"; | ||
| import js from "@eslint/js"; | ||
| import { dirname } from "path"; | ||
| import { fileURLToPath } from "url"; | ||
|
|
||
| const __filename = fileURLToPath(import.meta.url); | ||
| const __dirname = dirname(__filename); | ||
|
|
||
| const compat = new FlatCompat({ | ||
| baseDirectory: __dirname, | ||
| recommendedConfig: js.configs.recommended, | ||
| }); | ||
|
|
||
| const eslintConfig = [ | ||
| ...compat.config({ | ||
| extends: ["eslint:recommended", "next/core-web-vitals"], | ||
| }), | ||
| ]; | ||
|
|
||
| export default eslintConfig; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "compilerOptions": { | ||
| "paths": { | ||
| "@/*": ["./src/*"] | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /** @type {import('next').NextConfig} */ | ||
| const nextConfig = { | ||
| reactStrictMode: true, | ||
| }; | ||
|
|
||
| export default nextConfig; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.