Docs
Documentation System Flow
Documentation System Flow
Content management and documentation rendering with Contentlayer and MDX
Overview
Manages the documentation system using Contentlayer and MDX for content management. Provides a structured way to create, organize, and render documentation pages with automatic navigation, table of contents, and static generation.
Main libraries/services:
contentlayer2- Content management and static generationMDX- Markdown with JSX componentsrehypeplugins for code highlighting and linkingremarkplugins for GitHub Flavored Markdown
File Map
š contentlayer.config.ts - Contentlayer configuration and document types
š config/docs.ts - Documentation navigation and sidebar configuration
š app/(docs)/docs/[[...slug]]/page.tsx - Dynamic documentation page renderer
š content/docs/ - MDX documentation files
š content/guides/ - Guide content files
š content/blog/ - Blog post files
š content/pages/ - Static page files
š components/docs/ - Documentation-specific components
š components/content/mdx-components.tsx - MDX component mapping
š lib/toc.ts - Table of contents generation
Step-by-Step Flow
Adding New Documentation Section
- Create new MDX file in
content/docs/directory - Add frontmatter with title and description
- Update
config/docs.tsto include new section in sidebar - Contentlayer automatically processes the file during build
- Static routes are generated for the new documentation page
Documentation Page Rendering
- User navigates to
/docs/[slug]URL app/(docs)/docs/[[...slug]]/page.tsxreceives slug parametersgetDocFromParamsfinds matching document fromallDocs- If document exists:
- Metadata is generated for SEO
- Table of contents is extracted from content
- Images are processed with blur data URLs
- MDX content is rendered with custom components
- Page is rendered with navigation and TOC sidebar
Content Processing Pipeline
- Contentlayer scans
content/directory for MDX files - Files are processed based on document type (Doc, Guide, Post, Page)
- Frontmatter is parsed and validated
- MDX content is transformed with plugins:
remarkGfmfor GitHub Flavored MarkdownrehypeSlugfor heading IDsrehypePrettyCodefor syntax highlightingrehypeAutolinkHeadingsfor heading links
- Static routes are generated for all documents
Navigation and Sidebar
config/docs.tsdefines navigation structure- Sidebar items are organized by categories
- Each item links to corresponding documentation page
- Active page highlighting based on current route
- Breadcrumb navigation for deep linking
Data Flow Diagram
[MDX Files] ā [Contentlayer] ā [Document Processing] ā [Static Generation] ā [Next.js Routes]
ā
[User Request] ā [Dynamic Route] ā [Document Lookup] ā [MDX Rendering] ā [Page Display]
ā
[Navigation Config] ā [Sidebar Generation] ā [Active State] ā [User Interface]
Document Types
Doc (Documentation)
{
title: string (required)
description?: string
published?: boolean (default: true)
}Guide
{
title: string (required)
description?: string
date: string (required)
published?: boolean (default: true)
featured?: boolean (default: false)
}Post (Blog)
{
title: string (required)
description?: string
date: string (required)
published?: boolean (default: true)
image: string (required)
authors: string[] (required)
categories: ("news" | "education")[] (required)
related?: string[]
}Page (Static)
{
title: string (required)
description?: string
}MDX Features
Custom Components
<Callout>- Alert boxes with different types<Steps>- Step-by-step instructions- Custom HTML element overrides
- Tailwind CSS styling support
Code Highlighting
- Syntax highlighting with
rehype-pretty-code - GitHub Dark theme
- Copy-to-clipboard functionality
- Line number support
Navigation Features
- Automatic heading links
- Table of contents generation
- Previous/Next page navigation
- Breadcrumb support
Configuration Structure
Sidebar Navigation
sidebarNav: [
{
title: "Category Name",
items: [
{
title: "Page Title",
href: "/docs/page-slug",
},
],
},
];Main Navigation
mainNav: [
{
title: "Documentation",
href: "/docs",
},
{
title: "Guides",
href: "/guides",
},
];Notes and TODOs
- ā Contentlayer integration with MDX processing
- ā Automatic static generation for all content
- ā Custom components and styling support
- ā Table of contents and navigation
- ā SEO metadata generation
- ā Code syntax highlighting
- ā ļø Current flows section only has placeholder content
- š Add search functionality for documentation
- š Implement documentation versioning
- š Add documentation analytics
- š Create documentation templates
- š Add multi-language support
- š Implement documentation feedback system