Skip to content
Merged
Show file tree
Hide file tree
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 Mar 18, 2025
9fd82b3
chore: further project setup
ahuseyn Mar 19, 2025
a6fe2ba
feat: pull flatListToHierarchical from faust
ahuseyn Mar 19, 2025
74b5fa5
feat: add BlockRenderer and DefaultBlock
ahuseyn Mar 19, 2025
7181ef4
feat: add new blocks
ahuseyn Mar 19, 2025
4b06ad9
feat: add more blocks
ahuseyn Mar 19, 2025
c013087
feat: add blocks index
ahuseyn Mar 19, 2025
a035b80
fix: add getInlineStyles for proper style handling
ahuseyn Mar 19, 2025
c514b39
fix: add data to default block
ahuseyn Mar 19, 2025
db21851
feat: add homepage and post data
ahuseyn Mar 20, 2025
f32d3ef
fix: autoPlay in CoreAudio
ahuseyn Mar 20, 2025
b7816d2
fix: update post data
ahuseyn Mar 20, 2025
0cb34ff
feat: add Caption component
ahuseyn Mar 20, 2025
512c11d
fix: add global style, fix mockRequest method
ahuseyn Mar 20, 2025
5d80160
chore: add readme
ahuseyn Mar 20, 2025
f9f7982
fix: add title to index
ahuseyn Mar 20, 2025
d2e42e3
fix: add customParser to BlockRenderer
ahuseyn Mar 20, 2025
7e0c1f2
fix: update post.json
ahuseyn Mar 20, 2025
b2ef8ac
fix: project structure in readme
ahuseyn Mar 21, 2025
30ccc9a
Update examples/next/render-blocks-pages-router/README.md
ahuseyn Mar 21, 2025
a9a3b68
Update examples/next/render-blocks-pages-router/README.md
ahuseyn Mar 21, 2025
7c2fed5
Update examples/next/render-blocks-pages-router/README.md
ahuseyn Mar 21, 2025
c205da6
feat: add nvmrc
ahuseyn Mar 24, 2025
ee3d42a
docs: add screenshot to the readme
ahuseyn Mar 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions examples/next/render-blocks-pages-router/.gitignore
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
1 change: 1 addition & 0 deletions examples/next/render-blocks-pages-router/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lts/*
71 changes: 71 additions & 0 deletions examples/next/render-blocks-pages-router/README.md
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
```

http://localhost:3000/ should render the blocks as shown below.

![Animated screenshot, scrolling down and revealing the blocks supported by this example rendered on the page.](./public/screenshot.gif)
20 changes: 20 additions & 0 deletions examples/next/render-blocks-pages-router/eslint.config.mjs
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;
7 changes: 7 additions & 0 deletions examples/next/render-blocks-pages-router/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"paths": {
"@/*": ["./src/*"]
}
}
}
6 changes: 6 additions & 0 deletions examples/next/render-blocks-pages-router/next.config.mjs
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;
Loading