Skip to content

Commit c39b4ac

Browse files
authored
[next]: Add data fetching and preview (#2154)
* init preview example * update gql client, add headers param * update template-hierarchy, add id and asPreview * add preview utility to @faustjs/nextjs package * initial * new templates * add homepage * style fixes * update uri expression * rename example name, add readme
1 parent 4056de6 commit c39b4ac

40 files changed

+2296
-30
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.*
7+
.yarn/*
8+
!.yarn/patches
9+
!.yarn/plugins
10+
!.yarn/releases
11+
!.yarn/versions
12+
13+
# testing
14+
/coverage
15+
16+
# next.js
17+
/.next/
18+
/out/
19+
20+
# production
21+
/build
22+
23+
# misc
24+
.DS_Store
25+
*.pem
26+
27+
# debug
28+
npm-debug.log*
29+
yarn-debug.log*
30+
yarn-error.log*
31+
.pnpm-debug.log*
32+
33+
# env files (can opt-in for committing if needed)
34+
.env*
35+
36+
# vercel
37+
.vercel
38+
39+
# typescript
40+
*.tsbuildinfo
41+
next-env.d.ts
42+
43+
package-lock.json
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Kitchen Sink Example
2+
3+
A comprehensive Next.js example showcasing FaustJS features including template hierarchy, data fetching, and WordPress integration.
4+
5+
## Features
6+
7+
- **Template Hierarchy**: Dynamic WordPress template mapping (single, page, archive, home)
8+
- **Data Fetching**: Server-side rendering with WordPress GraphQL data
9+
- **Preview Mode**: WordPress post/page previews with authentication
10+
- **Fallback Routing**: Catch-all routing with blocking fallback strategy
11+
- **Dynamic Loading**: Code-split templates for optimal performance
12+
13+
## Quick Start
14+
15+
1. Install dependencies:
16+
17+
```bash
18+
npm install
19+
```
20+
21+
2. Configure environment variables:
22+
23+
```bash
24+
cp .env.example .env.local
25+
# Add your NEXT_PUBLIC_WORDPRESS_URL
26+
```
27+
28+
3. Run development server:
29+
```bash
30+
npm run dev
31+
```
32+
33+
## Architecture
34+
35+
- Uses `[[...identifier]].js` for dynamic WordPress routing
36+
- Template queries are fetched server-side using `@faustjs/data-fetching`
37+
- WordPress templates are dynamically loaded based on content type
38+
- Supports both static generation and draft previews
39+
40+
Perfect for testing FaustJS capabilities and as a reference implementation.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { FlatCompat } from "@eslint/eslintrc";
2+
import js from "@eslint/js";
3+
import { dirname } from "path";
4+
import { fileURLToPath } from "url";
5+
6+
const __filename = fileURLToPath(import.meta.url);
7+
const __dirname = dirname(__filename);
8+
9+
const compat = new FlatCompat({
10+
baseDirectory: __dirname,
11+
recommendedConfig: js.configs.recommended,
12+
});
13+
14+
const eslintConfig = [
15+
...compat.config({
16+
extends: ["eslint:recommended", "next/core-web-vitals"],
17+
}),
18+
];
19+
20+
export default eslintConfig;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"compilerOptions": {
3+
"paths": {
4+
"@/*": ["./src/*"]
5+
}
6+
}
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {
3+
reactStrictMode: true,
4+
};
5+
6+
export default nextConfig;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "@faustjs/kitchen-sink-example",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"dev": "next dev",
7+
"build": "next build",
8+
"start": "next start",
9+
"lint": "next lint"
10+
},
11+
"dependencies": {
12+
"@faustjs/nextjs": "workspace:*",
13+
"@faustjs/template-hierarchy": "workspace:*",
14+
"@faustjs/data-fetching": "workspace:*",
15+
"graphql": "^16.11.0",
16+
"graphql-tag": "^2.12.6",
17+
"next": "15.2.4",
18+
"react": "^19.0.0",
19+
"react-dom": "^19.0.0"
20+
},
21+
"devDependencies": {
22+
"@eslint/eslintrc": "^3",
23+
"@tailwindcss/postcss": "^4",
24+
"eslint": "^9",
25+
"eslint-config-next": "15.2.4",
26+
"tailwindcss": "^4"
27+
}
28+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const config = {
2+
plugins: ["@tailwindcss/postcss"],
3+
};
4+
5+
export default config;
25.3 KB
Binary file not shown.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import Link from "next/link";
2+
3+
export function BlogPostItem({ post }) {
4+
const { title, date, excerpt, uri, featuredImage } = post ?? {};
5+
6+
return (
7+
<article className='container max-w-4xl px-10 py-6 mx-auto rounded-lg shadow-sm bg-gray-50 mb-4'>
8+
<time dateTime={date} className='text-sm text-gray-600'>
9+
{new Date(date).toLocaleDateString("en-US", {
10+
year: "numeric",
11+
month: "long",
12+
})}
13+
</time>
14+
15+
{featuredImage && (
16+
<img src={featuredImage?.node?.sourceUrl} alt='' className='w-full h-48 object-cover rounded-t-lg mt-2 mb-4' />
17+
)}
18+
19+
<h2 className='mt-3'>
20+
<Link href={uri} className='text-2xl font-bold hover:underline'>
21+
{title}
22+
</Link>
23+
</h2>
24+
25+
<div className='mt-2 mb-4' dangerouslySetInnerHTML={{ __html: excerpt }} />
26+
27+
<Link href={uri} className='hover:underline text-orange-600 mt-4'>
28+
Read more
29+
</Link>
30+
</article>
31+
);
32+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/* eslint-disable @next/next/no-html-link-for-pages */
2+
import Link from 'next/link';
3+
4+
export default function Header() {
5+
return (
6+
<header className="bg-gray-800 text-white py-4 px-8">
7+
<div className="flex justify-between items-center max-w-4xl mx-auto">
8+
<div className="text-3xl font-semibold">
9+
<Link href="/">Headless</Link>
10+
</div>
11+
12+
<nav className="space-x-6">
13+
<Link href="/" className="text-lg hover:underline">
14+
Home
15+
</Link>
16+
</nav>
17+
</div>
18+
</header>
19+
);
20+
}

0 commit comments

Comments
 (0)