Introduction
Learn how to use Fumadocs MDX in your documentation
Introduction
Fumadocs MDX is the official content source of Fumadocs.
It provides the tool for Next.js to transform content into type-safe data, similar to Contentlayer and Content Collections.
Getting Started
Setup Fumadocs MDX for your Fumadocs application.
This package requires Fumadocs core.
Add the plugin to your next.config.mjs file.
Defining Collections
Collection refers to a collection containing a certain type of files, there's two types of collections:
- doc: Markdown/MDX documents
- meta: JSON files
For example, a doc collection will include only the .md files:
Fumadocs MDX will build collections into arrays of type-safe data, accessible in your Next.js app.
You can define and configure collections by creating a config file: source.config.ts.
Only files in the directory specified in dir will be included in the collection.
For Fumadocs to work, you can use defineDocs:
defineDocs defines the required collections for Fumadocs.
It is same as the config below:
The two collections together will include all Markdown/MDX and JSON files under your content/docs directory.
Output Folder
Once you run next dev or next build, it generates a .source folder in root directory.
The folder contains all output data and its types, you should add it to .gitignore.
ESM Only
The Next.js config must be a .mjs file since Fumadocs is ESM-only.
The fumadocs-mdx command generates types for .source folder without running Next.js, you can add it as a post install script.
Accessing Collections
Collection Entry is an entry in the output array of a collection, it can have a different type/shape depending on the collection type and schema.
You can access the entries of collection from .source folder, with its original name:
To integrate with Fumadocs, create:
We imported the .source folder with @/.source, you can also change it to your own import alias.
createMDXSource takes an array of doc and meta entry, and convert them into Fumadocs compatible format.
Good to Know
meta entries are only taken for building page trees.
You can leave the second parameter an empty array if meta.json isn't used:
Start Server
A .source folder should be created. You can log and see if it is loaded correctly.
See Organizing Pages to learn how to organize your pages.
Usage
Generally, you'll interact with Fumadocs MDX through the Source object (output of loader).
To render the page, use page.data.body as a component.
Multiple Collections
You can define other collections, see Collections for available options.
And use loader for a simple way to interact with collection entries.
FAQ
Built-in Properties
These properties are exported from MDX files by default.
| Property | Description | 
|---|---|
| frontmatter | Frontmatter | 
| toc | Table of Contents | 
| structuredData | Structured Data, useful for implementing search | 
MDX Plugins
See MDX Options.
Last updated on
