Generates Next.js/Fumadocs docs content routes into a custom JSON for proxy.ts middleware redirects
124
Generates docs-routes.json containing a list of root docs sections + labels, private sections, public exceptions and private pages from the private frontmatter or meta flags in Fumadocs content/docs/.
Its output is a lightweight JSON file, intended for a Fumadocs project's proxy.ts to import and use for auth-gated server-side redirects and session checks.
Fumadocs content folders set the flag in meta.json and pages set it in their frontmatter.
GitHub Repository
https://github.com/weaponsforge/fumadocs-routes
Fumadocs documentation project (tested for Next.js - App Router. Other options/variations are untested)
Fumadocs source.config.ts extended to hold the private field in its meta.json and frontmatter (pages).
source.config.ts
import { metaSchema, pageSchema } from 'fumadocs-core/source/schema'
import { defineConfig, defineDocs } from 'fumadocs-mdx/config'
import { z } from 'zod'
export const docs = defineDocs({
dir: 'content/docs',
docs: {
schema: pageSchema.extend({
private: z.boolean().default(false),
}),
},
meta: {
schema: metaSchema.extend({
private: z.boolean().default(false),
}),
},
})
Pull the "latest" production image.
docker pull weaponsforge/fumadocs-routes
Navigate to a Next.js (App Router) - Fumadocs project using the command line.
Take note of the "content/docs/" folder location in the Fumadocs project. Fumadocs initializes it by default in /<project-root>/content/docs. Example:
fumadocs-project/
├── content/ # MDX docs content
| └── docs/
| ├── characters/
| | ├── meta.json
| | ├── index.mdx
| | ├── knight.mdx
| | ├── wizard.mdx
| | ├── elf.mdx
| └── information/
| ├── meta.json
| ├── index.mdx
| └── training.mdx
├── package.json
├── ...
Mark private folders and pages.
Add "private": true in the meta.json of main folders (sections) or nested sub-folders that you'd like to keep private.
Add private: true in the frontmatter of *.mdx files for specific pages that you'd like to keep private.
INFO: Marking them private does not automatically make them private in Fumadocs. You'd need to set its
proxy.tsfor auth gates (eg., configure Google OAuth2 sign-in, session checks) and server-side redirects using the routes list output in step #5.
Run to generate docs-routes.json
eg., in PowerShell (within a Fumadocs project root folder):
docker run --rm -v ${pwd}:/opt/app weaponsforge/fumadocs-routes
| Option | Description |
|---|---|
--docs, -d | Fumadocs docs folder path. Default: <root>/content/docs |
--output,-o | Folder to write docs-routes.json into. A file path is rejected,the file is always named docs-routes.json. Missing folders are created.Default: <root> |
--strict | A top-level folder without meta.json is an error instead of a warning. See Validation.Default: off |
<root> is the nearest folder with a package.json, searched from the working directory upwards.Sample docs-routes.json
{
"sections": ["characters", "secrets", "stats-calculator", "weapons"],
"section_labels": {
"characters": "MU Online characters",
"secrets": "MU Online secrets",
"stats-calculator": "Character Stats Calculator",
"weapons": "MU Online weapons"
},
"private_sections": ["secrets", "stats-calculator"],
"public_exceptions": ["secrets", "secrets/skill-tips"],
"private_pages": ["characters/elf"]
}
| Key | Contents |
|---|---|
sections | Folders served at /docs/<folder> whose meta.json has root: true: the non-group children of content/docs, plus folders inside top-level groups (content/docs/(extra)/items → items). Nested root: true folders such as characters/classes are not sections, because sections only key on the first URL segment. |
section_labels | One label per section, used for llms.txt headings. The first non-empty value of: the meta.json description, the index.mdx description, the slug. |
private_sections | URL prefixes of the topmost private, non-group folders (can be nested, e.g. characters/wizards). Every URL under a prefix is gated, including URLs that don't exist. |
public_exceptions | Exact slugs of public pages under a private prefix. |
private_pages | Exact slugs of private pages not covered by a prefix: a private page in a public section, or the pages of a private (group) folder. |
Slugs follow Fumadocs URLs: (group) segments, the .mdx/.md extension and a trailing index are dropped.
Content type
Image
Digest
sha256:6aea7efb1…
Size
59.3 MB
Last updated
10 days ago
docker pull weaponsforge/fumadocs-routes