Fumadocs in Nextjs
An intergration guide
Welcome to the docs! You can start writing documents in /content/docs.
What is Next?
Integration of FumaDocs into a Next.js 15 Project
FumaDocs has been integrated into your project to provide an opinionated documentation structure and interface. Here’s how it is set up in your repository:
Core FumaDocs Components
fumadocs-mdxandfumadocs-uiPackages:
- These are the primary libraries powering documentation rendering and theming.
fumadocs-mdxprocesses MDX files for dynamic documentation pages.fumadocs-uiprovides prebuilt layouts, MDX components, and utilities for a cohesive documentation interface.
- MDX Source Handling (
lib/source.ts):
- Uses
fumadocs-mdxto parse documentation stored in thecontent/docsfolder. - The
sourceobject fromfumadocs-core/sourceprovides methods for fetching page data (getPage) and generating route parameters (generateParams).
- Documentation Structure:
- Content is written in MDX format and stored in the
content/docsfolder. - Metadata such as
titleanddescriptionis specified in frontmatter, allowing FumaDocs to handle them dynamically.
Next.js Integration
- Page and Layout Customization:
- Dynamic Routing (
app/docs/[[...slug]]/page.tsx):- This file dynamically serves documentation pages based on the slug.
- Pages are built using
DocsPage,DocsTitle,DocsDescription, andDocsBodyfromfumadocs-ui/page. - Non-existent pages trigger the
notFoundmethod.
- Layouts (
app/docs/layout.tsxandapp/(home)/layout.tsx):- Use
DocsLayoutandHomeLayoutfromfumadocs-ui/layoutsto structure the documentation and homepage.
- Use
- MDX Processing (
next.config.mjs):
- Configured with
createMDX()fromfumadocs-mdxfor seamless MDX support in the project.
- Static Generation:
generateStaticParamsandgenerateMetadataensure static site generation compatibility by preparing routes and metadata for each page.
Styling and Tailwind Integration
- Tailwind Preset:
- Tailwind is extended using the
fumadocs-ui/tailwind-pluginto add FumaDocs-specific styles. - Custom fonts (Mona Sans and Hubot Sans) are registered as CSS variables (
--font-mona-sans,--font-hubot-sans) and used in the Tailwind configuration forsansanddisplayfont families.
- Custom Styles (
app/global.css):
- Tailwind base, components, and utilities are applied.
- Global typography and theme colors are defined, leveraging Tailwind’s
@applyfor maintainable styling.
Custom Components
You have replaced parts of the default FumaDocs UI with custom components:
DocsBody,DocsTitle, andDocsDescriptionprovide more control over styling using your own Tailwind classes.
Search and Navigation
- Search API (
app/api/search/route.ts):
- Built using
fumadocs-core/search/server, enabling server-side search functionality for the documentation.
- Navigation Configuration (
app/layout.config.tsx):
- Centralized configuration for navigation links and titles ensures a consistent header and sidebar experience.
How It Works End-to-End
- Routing:
- Users visiting
/docsaccess a dynamic MDX-based documentation page. - Pages are dynamically rendered based on the file structure in
content/docs.
- Rendering:
- FumaDocs handles MDX parsing and injects custom React components for enhanced interactivity.
- Styling:
- Tailwind handles global and utility-based styling, enhanced with FumaDocs presets.
- Extensibility:
- You can modify FumaDocs components or layouts and extend functionality with Tailwind or React.
This setup ensures a developer-friendly and extendable documentation platform with FumaDocs seamlessly integrated into the Next.js 15 framework.