Use these docs as a template

Lift this docs site into another Next.js 16 project: the dependencies, the files to copy, the adapters for a design system, and adding a page.

Updated

This docs site is built on the stack generaltranslation.com/docs runs: fumadocs with the notebook layout and MDX pages. It imports nothing from the hub's shell or the directions, so the folder lifts into another Next.js 16 project, and every pattern carries over to gt-cloud and back.

The dependencies

pnpm add fumadocs-core@16.16.1 fumadocs-ui@16.16.1 fumadocs-mdx@15.4.6
pnpm add -D @types/mdx

These are the versions gt-cloud pins. fumadocs-ui 16 needs Next.js 16 and React 19.2, and it is Tailwind 4 only. Prototemplate pins next to 16.2.12 so an install cannot move it to 16.3, which holds memory for every prerendered page during a build.

Add "postinstall": "fumadocs-mdx" to package.json, so a fresh install writes .source/ before the first type check.

The files to copy

PathWhat it is
source.config.tsThe collection: content/docs, processed Markdown kept for the twins, tokenizeTimeLimit: 0 for Shiki, and the remark plugin for pages that include repository files
src/lib/remark-handbook.tsThe plugin a page that shows a repository Markdown file needs: it drops the file's h1, resolves its relative links and prints raw HTML as text
src/lib/source.tsThe loader at /docs, with the sidebar's icon names
content/docs/The MDX pages and a meta.json per folder: the sidebar's tabs, folders and order
src/app/docs/layout.tsx (the notebook layout and the provider), [[...slug]]/page.tsx (one page) and docs.css
src/components/docs/The sidebar footer, the theme button, the page actions and the sidebar motion; demos/ holds the live plates, each loaded through demos/lazy.tsx
src/app/api/search/route.tsThe static search index
src/app/md/, src/app/llms.txt/, src/app/llms-full.txt/The Markdown twins and the agent files
src/lib/seo/seoRoute, the policy, the JSON-LD builders and the card

In next.config.ts, wrap the config with createMDX() from fumadocs-mdx/next and add the twin rewrites, which send /docs.md, /docs/<slug>.md and /docs/<folder>/<slug>.md to the twin route under /md/docs. In tsconfig.json, map @/.source/* to ./.source/*, and add .source/ to .gitignore.

The adapters

A project with its own design system needs these adapters, all in docs.css, all unlayered rules so they outrank Tailwind's layered utilities without !important. The header of docs.css lists them in order.

  1. The font tokens. Tailwind's theme layer would reset --font-sans and --font-mono to its own stacks for the whole document, so the sheet's @theme block points them at the site's type tokens (--pt-text, --pt-mono, --pt-display).
  2. The theme switch. fumadocs styles its dark mode on a .dark class that next-themes writes. Prototemplate's theme is html[data-theme], so RootProvider gets theme={{ enabled: false }}, docs.css redefines the dark variant on :root[data-theme='dark'], and fumadocs' two dark Shiki rules are repeated under that selector. pnpm lint:practices fails a .dark selector anywhere in src/.
  3. The token bridge. fumadocs reads --color-fd-background, --color-fd-foreground, --color-fd-border and the rest. docs.css sets them from the site's tokens on :root:has(#nd-notebook-layout), so they exist only while the docs layout is in the document.
  4. The weight cap. fumadocs and its typography plugin draw headings at 600 and 700. Prototemplate's Inter stops at 500, so one rule sets 500 on the docs' headings, labels and strong text.
  5. The radius map. fumadocs rounds its panels with rounded-lg to rounded-2xl; inside the docs those resolve to the site's card corner.
  6. Flat surfaces and the sidebar's marks. The docs' surfaces are flat, and the sheet draws the rails and pills that SidebarMotion moves in the sidebar.

Adding a page

A page lives in a tab, and inside a tab in a folder. Choose both first, because the folder decides the URL and the sidebar row.

TabFolderURL of <slug>.mdx
Guidecontent/docs/(guide)//docs/<slug>
Componentscontent/docs/components/, then one of (fields), (drawings), (language-and-motion), (marks-and-heads)/docs/components/<slug>
Craftcontent/docs/craft//docs/craft/<slug>
Engineeringcontent/docs/engineering//docs/engineering/<slug>
Internalscontent/docs/(internals)/, then one of (routes), (tooling), (publishing)/docs/<slug>
  • A folder named in parentheses, such as (tooling), is a folder group: it draws a sidebar folder and adds no URL segment, so content/docs/(internals)/(tooling)/gates.mdx serves /docs/gates. A plain folder such as craft adds its name to the URL.
  • A tab is a folder whose meta.json sets "root": true. fumadocs draws every root folder as a tab in the menu at the top of the sidebar, with the title, description and icon of that meta.json. The root content/docs/meta.json lists the five tabs in order.
  • Write <slug>.mdx in the chosen folder with a title and a description of 50 to 160 characters, then add the slug to that folder's meta.json pages list where the sidebar should show it. A root folder lists its own index as its first row. A folder that is not a root takes its index.mdx as the folder row's link, so its meta.json leaves index out.
  • A new folder group gets its own meta.json with a title, the pages in order and "defaultOpen": true when it should start open, and the parent's meta.json lists it by its name, parentheses included.
  • A script that turns a file path into a route drops every (name) segment, as scripts/build/updated.mjs and scripts/lint/registries.mjs do. A script that keeps it looks for /docs/(internals)/gates, a page that does not exist.

The route, the sidebar, the search index, the table of contents, the Markdown twin, /llms.txt, the sitemap and the social card follow from the file. In this repository also add its row to src/components/docs/pages.ts in sidebar order, with the URL after /docs/ as its slug (components/dither, gates), and run pnpm build:updated. pnpm lint:registries follows every meta.json from the root and fails when the rows, their titles or their descriptions differ from the files. A page under /docs/handbook is held to the handbook registry instead.

A page that shows a repository Markdown file, as each handbook page does, includes it with fumadocs-mdx's tag, <include cwd>docs/handbook/glossary.md</include>, so the file stays the one source. To set a live figure between two sections, include the file one heading at a time; the build then fails if the page leaves a heading of the file out.

A page that mounts a live component imports it from src/components/docs/demos/lazy.tsx, which wraps each plate in next/dynamic. fumadocs-mdx imports every page into one route, so a plate imported directly would load its code and its stylesheet on every docs page. A sentence beside each plate says what it shows, since the Markdown twin prints the plate as a bare tag. List the files the plate runs under sources: in the frontmatter, so pnpm build:updated dates the page when they change.

Traps

This site met each of these traps on fumadocs and Next.js 16, and each line gives the fix it uses. Docs site traps on Next.js 16 and fumadocs explains each one with its measurements.

  • A redirect() thrown inside a page render paints the layout above the page at the old URL first. A click on a docs folder URL painted the layout with no article, then replaced it about 280 ms later, so every link the site renders points at the leaf page (links that point at leaf pages).
  • A sidebar whose rail and current-row tint are drawn in a mount effect shows neither until hydration. fumadocs' own rails sit inboard of the drawn path and jump sideways at hydration, so only the mark whose geometry matches, the row tint, is shown before #nd-sidebar[data-sb-ready] (marks that exist at first paint).
  • Shiki stops tokenizing a line after 500 ms by default, so two builds of one page can differ. On ten code fences a forced limit gave 64 coloured spans in one pipeline and 47 in another, and tokenizeTimeLimit: 0 in source.config.ts gives the same output on every run (code highlighting across builds).
  • Tailwind's preflight sets font-feature-settings on html from a theme token the docs sheet never set, so every docs element computed normal and lost liga and calt while the family was right (features that compute normal).
  • A docs rule that sets a global token leaks to other routes. React keeps a route's stylesheet in the document after a client navigation, so the token bridge is scoped to :root:has(#nd-notebook-layout) and its values exist only while the docs layout is in the document (features that compute normal).
  • An ID inside an :is() list lifts the whole list's specificity: one #nd-notebook-layout among the shell's root classes would raise every rule built on the list from (0,1,1) to (1,0,1), and those base rules would then beat component rules across the site. A docs root that joins those lists joins as a class, at (0,1,0) like the roots already there (specificity of an is() list).
  • The docs sheet loads no components layer, so the typography plugin's .prose rules land in the utilities layer and tie with utilities at (0,1,0). The rule emitted later wins, and a table-of-contents row that carries both prose and text-sm gets text-sm (the typography plugin in the utilities layer).
  • Tailwind 4's rounded-full is calc(infinity * 1px), which Chrome computes as a 33,554,400 px corner, so a corner lint reports that number. A 4 by 4 dot takes 50% (the full round corner).
  • fumadocs and its typography plugin draw headings at 600 and 700, and a b or strong inside weight 500 computes 700 through the browser's bolder. The weight cap sets 500 on the docs' headings, labels and strong text (what fumadocs leaves for the lints).
  • fumadocs portals the search dialog and its popovers into body, outside the layout. An adapter scoped to #nd-notebook-layout alone misses them, so the weight cap also names [role='dialog'] and [data-radix-popper-content-wrapper], and a lint that reads the page at rest never opens them (markup that hides from a lint).
  • The Markdown twin prints a live plate as a bare tag, so every plate has a sentence beside it that says what it shows.

The search is fumadocs' Orama index, served as one static JSON file built with the site and searched in the browser. For a few dozen pages that is the whole job, and it works in development. gt-cloud runs Pagefind after next build instead, because it indexes hundreds of pages in many locales; switch when the index grows past what one download should carry.

The checks

Run pnpm lint:registries, pnpm lint:seo, pnpm exec tsc --noEmit and the build. On the running site, pnpm lint:type:live and pnpm lint:radius:live confirm the adapters hold, and pnpm lint:seo:live against next start reads every page's head, card and twin.

On this page