Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 7 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ package-lock.json
tsconfig.tsbuildinfo
.next/

# contentlayer
.contentlayer
# qino
qino/_generated/

# generated by scripts/generate-markdown.mjs
# generated by qino build (llms.txt, its sections, llms-full.txt, index.md)
/public/**/*.md
/public/llms.txt
/public/**/llms.txt
/public/llms-full.txt

# generated by scripts/generate-sitemap.mts
/public/sitemap.xml
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.18.1
24
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
pnpm-lock.yaml
.cache/
.contentlayer/
qino/_generated/
.next/
next-env.d.ts
public/**/*.md
public/llms*.txt
public/**/llms.txt
74 changes: 0 additions & 74 deletions contentlayer.config.ts

This file was deleted.

2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import eslintPluginReact from "eslint-plugin-react"

export default tseslint.config(
{
ignores: [".next/**", ".contentlayer/**", "public/**", "next-env.d.ts"],
ignores: [".next/**", "qino/_generated/**", "public/**", "next-env.d.ts"],
},

tseslint.configs.recommendedTypeChecked,
Expand Down
105 changes: 105 additions & 0 deletions next.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,51 @@
import type { NextConfig } from "next"
import withBundleAnalyzer from "@next/bundle-analyzer"
import { markdownFirstAccept } from "./src/lib/markdown-accept"

// Agent-ready Markdown, after qino's Next.js recipe:
// https://www.qino.works/docs/guide/agent-ready-content/next-js

// Doc pages with Markdown, as `qino/items/pages.ts` declares them. A slug never
// holds a `.`, which keeps Markdown URLs out of the page patterns.
const TOP_LEVEL_PAGE = "/:page(get-started|faqs|ts|migrate-v7-to-v8)"
const SECTIONS = ["integrations", "advanced-usage"]
const DOC_PAGE = "/docs/:slug([^.]+)"

// The page's path, its Markdown URL, and the route handler that answers both.
// `markdownSource` matches the Markdown URL when its slug spans segments.
type MarkdownPage = {
source: string
markdownUrl: string
markdownSource?: string
handler: string
}
const markdownPages: Array<MarkdownPage> = [
{
source: TOP_LEVEL_PAGE,
markdownUrl: "/:page.md",
markdownSource: `${TOP_LEVEL_PAGE}.md`,
handler: "/api/md/:page",
},
{ source: "/docs", markdownUrl: "/docs.md", handler: "/api/md/docs" },
{
source: DOC_PAGE,
markdownUrl: "/docs/:slug.md",
markdownSource: "/docs/:slug+.md",
handler: "/api/md/docs/:slug+",
},
...SECTIONS.flatMap((section) => [
{
source: `/${section}`,
markdownUrl: `/${section}.md`,
handler: `/api/md/${section}`,
},
{
source: `/${section}/:slug([^/.]+)`,
markdownUrl: `/${section}/:slug.md`,
handler: `/api/md/${section}/:slug`,
},
]),
]

const nextConfig: NextConfig = {
typescript: {
Expand All @@ -12,6 +58,65 @@ const nextConfig: NextConfig = {
},
reactStrictMode: true,
pageExtensions: ["ts", "tsx", "js", "jsx", "md", "mdx"],
// The API routes under `/api/md` render on request and read content then.
// `/api/md` also reads `public/index.md`, which `qino build` writes.
outputFileTracingIncludes: {
"/api/md": ["./public/index.md"],
"/api/md/**": ["./src/content/**/*"],
},
async rewrites() {
return {
// `beforeFiles` runs before prerendered pages, which would answer first.
beforeFiles: [
{ source: "/", has: markdownFirstAccept, destination: "/api/md" },
...markdownPages.flatMap(
({ source, markdownUrl, markdownSource, handler }) => [
{ source: markdownSource ?? markdownUrl, destination: handler },
{ source, has: markdownFirstAccept, destination: handler },
]
),
],
// `fallback` runs after pages, public files and dynamic routes, so it
// only matches paths nothing answers: Markdown requests for them get the
// Markdown 404.
fallback: [
{ source: "/:path(.+\\.md)", destination: "/api/md/missing" },
{
source: "/:path*",
has: markdownFirstAccept,
destination: "/api/md/missing",
},
],
}
},
async headers() {
const pages: Array<{
source: string
markdownUrl: string
links?: Array<string>
}> = [
{
source: "/",
markdownUrl: "/index.md",
links: ['</llms.txt>; rel="describedby"'],
},
...markdownPages,
]
return pages.map(({ source, markdownUrl, links = [] }) => ({
source,
headers: [
{
key: "Link",
value: [
`<${markdownUrl}>; rel="alternate"; type="text/markdown"`,
...links,
].join(", "),
},
// The same URL answers HTML or Markdown, by `Accept`.
{ key: "Vary", value: "Accept" },
],
}))
},
async redirects() {
const legacySite =
"https://react-hook-form-website-git-leagcy-hook-form.vercel.app"
Expand Down
27 changes: 14 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
"name": "react-hook-form-website",
"description": "React hooks for form validation without the hassle.",
"version": "6.0.1",
"type": "module",
"author": "beier luo",
"dependencies": {
"@hookform/devtools": "4.4.0",
"@mdx-js/loader": "^2.3.0",
"@mdx-js/mdx": "3.1.1",
"@mdx-js/react": "^3.1.1",
"@qino/cms": "0.25.0",
"class-variance-authority": "^0.6.1",
"clsx": "^1.2.1",
"contentlayer2": "0.5.8",
"little-state-machine": "^4.8.1",
"next": "16.4.5",
"next-contentlayer2": "0.5.8",
"next-themes": "^0.2.1",
"prism-react-renderer": "^2.4.1",
"prismjs": "^1.30.0",
Expand All @@ -26,14 +26,15 @@
"remark-custom-heading-id": "^2.0.0",
"remark-emoji": "^5.0.2",
"remark-gfm": "^4.0.1",
"sortablejs": "1.15.0"
"sortablejs": "1.15.0",
"zod": "4.6.7"
},
"devDependencies": {
"@next/bundle-analyzer": "16.4.2",
"@types/eslint-plugin-jsx-a11y": "6.10.0",
"@types/eslint__eslintrc": "2.1.2",
"@types/mdx": "2.0.14",
"@types/node": "20.17.10",
"@types/node": "24.19.2",
"@types/react": "19.3.0",
"@types/react-dom": "19.3.0",
"@types/react-helmet": "^6.1.11",
Expand All @@ -46,6 +47,7 @@
"husky": "^8.0.3",
"lint-staged": "^13.3.0",
"prettier": "^3.9.10",
"tsx": "4.23.15",
"typescript": "^5.9.3",
"typescript-eslint": "8.72.0"
},
Expand All @@ -55,22 +57,21 @@
],
"license": "MIT",
"scripts": {
"analyze": "contentlayer2 build && cross-env ANALYZE=true next build --webpack",
"build": "contentlayer2 build && pnpm run markdown && next build",
"dev": "contentlayer2 build && pnpm run markdown && pnpm run --parallel \"/^dev:/\"",
"dev:content": "contentlayer2 dev",
"dev:next": "next dev",
"analyze": "qino build && cross-env ANALYZE=true next build --webpack",
"build": "qino build && pnpm run sitemap && next build",
"dev": "qino build && pnpm run sitemap && next dev",
"format": "prettier . --check",
"format:fix": "prettier . --write",
"lint": "eslint src",
"lint:fix": "eslint src --fix",
"markdown": "node scripts/generate-markdown.mjs",
"sitemap": "tsx scripts/generate-sitemap.mts",
"seo:check": "pnpm run build && node scripts/check-seo.mjs",
"lint:ci": "contentlayer2 build && next typegen && eslint src",
"lint:ci": "qino lint && next typegen && eslint src",
"now-build": "pnpm run build",
"start": "next start",
"typecheck": "tsc --noEmit",
"typecheck:ci": "contentlayer2 build && next typegen && tsc --noEmit",
"test": "tsx --test scripts/*.test.mts",
"typecheck:ci": "next typegen && tsc --noEmit",
"prepare": "husky install"
},
"lint-staged": {
Expand Down
Loading