一键导入
fumadocs-mdx
// Configure and manage Fumadocs MDX content collections, including schema definition, type generation, and file imports
// Configure and manage Fumadocs MDX content collections, including schema definition, type generation, and file imports
Create and configure Fumadocs projects using CLI, selecting frameworks, content sources, and UI components
Build and deploy Fumadocs documentation sites, supporting static export, PDF, RSS, and more
Build documentation sites using Headless components library, including navigation, TOC, search API, and content collections
Configure internationalization support for Fumadocs, including multi-language routing and content organization
Configure and integrate document search engines for Fumadocs, supporting Orama, Algolia, Mixedbread, and other solutions
Customize documentation appearance and layouts using Fumadocs UI theme and component library
| name | Fumadocs MDX |
| description | Configure and manage Fumadocs MDX content collections, including schema definition, type generation, and file imports |
Manage Fumadocs content collections and MDX documents.
Markdown/MDX document files:
import { defineCollections } from 'fumadocs-mdx/config';
import { z } from 'zod';
export const blog = defineCollections({
type: 'doc',
dir: './content/blog',
schema: z.object({
title: z.string(),
date: z.string().optional(),
tags: z.array(z.string()).default([]),
featured: z.boolean().default(false),
}),
mdxOptions: {
remarkPlugins: [remarkAdmonition()],
rehypePlugins: [rehypeCode()],
},
});
JSON/YAML metadata files:
export const metaFiles = defineCollections({
type: 'meta',
dir: './content/meta',
schema: z.object({
name: z.string(),
url: z.string(),
description: z.string().optional(),
}),
files: ['config.json', 'meta/*.json'],
});
schema: z.object({
title: z.string().min(10),
description: z.string().max(200),
published: z.coerce.date(),
author: z.string(),
});
schema: (ctx) => {
return z.object({
title: z.string(),
path: z.string().default(ctx.path),
filename: z.string().default(ctx.filename),
});
}
Supports standard Schema-compatible libraries, such as Zod.
import { applyMdxPreset } from 'fumadocs-mdx/mdx';
export const docs = defineCollections({
type: 'doc',
mdxOptions: applyMdxPreset({
remarkPlugins: [remarkAdmonition()],
rehypePlugins: [rehypeCode()],
}),
});
mdxOptions: {
// Completely custom
remarkPlugins: [remarkAdmonition()],
rehypePlugins: [rehypeCode()],
}
export const docs = defineDocs({
docs: {
postprocess: {
includeProcessedMarkdown: true,
},
},
});
Access:
const page = await page.data.getText('processed');
// Use processed markdown
const html = await page.data.getHtml();
export const docs = defineDocs({
docs: {
postprocess: {
valueToExport: ['metadata', 'toc'],
},
},
});
Access in MDX files:
// content/docs/guide.mdx
export const metadata = {
title: 'My Guide',
date: '2024-01-01',
};
export const toc = {
heading: 'Getting Started',
};
Import in other files:
import { metadata, toc } from './guide.mdx';
export default defineDocs({
dir: 'content/docs',
docs: {
dir: 'guides',
},
meta: {
dir: 'metadata',
},
blog: {
dir: 'content/blog',
},
});
export default defineDocs({
dir: 'content/docs',
collections: {
posts: defineCollections({
type: 'doc',
dir: 'content/blog',
}),
meta: defineCollections({
type: 'meta',
dir: 'metadata',
}),
},
});
npx fumadocs-mdx typegen
npx fumadocs-mdx typegen --skip-dev-server
npx fumadocs-mdx typegen --out-file src/types.d.ts
{
"scripts": {
"typegen": "fumadocs-mdx typegen"
}
}
import { include } from 'fumadocs-mdx/include';
export const sharedContent = include({
path: './content/shared/intro.mdx',
});
export const footerContent = include({
path: './content/shared/footer.mdx',
});
export const docs = defineCollections({
type: 'doc',
dir: './content/docs',
dynamic: true,
});
import { include } from 'fumadocs-mdx/include';
export const components = include({
path: './content/components/*.mdx',
});
export const blog = defineCollections({
type: 'doc',
dir: './content/blog',
async: true,
schema: z.object({
title: z.string(),
}),
});
export const docs = defineCollections({
type: 'doc',
dir: './content/docs',
async: false,
});
---
title: "My Document"
description: "A brief description"
date: "2024-01-01"
tags: ["guide", "tutorial"]
draft: false
---
# My Document
Content here...
---
title: "API Reference"
apiVersion: "1.0.0"
endpoint: "/api/v1/users"
---
# API Reference
import { remarkMath } from 'fumadocs-mdx/mdx';
import { rehypeKatex } from 'rehype-katex';
export const docs = defineDocs({
type: 'doc',
mdxOptions: {
remarkPlugins: [remarkMath()],
rehypePlugins: [rehypeKatex()],
},
});
import { remarkMermaid } from 'fumadocs-mdx/mdx';
export const docs = defineDocs({
type: 'doc',
mdxOptions: {
remarkPlugins: [remarkMermaid()],
},
});
```mermaid
graph LR
A[Start] --> B{Decision}
B -->|Yes| C[Action 1]
B -->|No| D[Action 2]
C --> E[End]
D --> E
### Twoslash
```typescript
import { remarkTwoslash } from 'fumadocs-mdx/mdx';
export const docs = defineDocs({
type: 'doc',
mdxOptions: {
remarkPlugins: [remarkTwoslash()],
},
});
function greet(name: string): string {
return `Hello, ${name}!`;
}
Reference Documentation: