Plan to Build the Documentation UI
The goal is to create a polished, navigable documentation section within the existing Next.js application that renders Markdown files from the docs/
directory.
1. Core Technology
- Markdown Rendering: We will use
react-markdown
along with theremark-gfm
plugin to parse the Markdown files and support GitHub Flavored Markdown (tables, etc.). - Syntax Highlighting: Code blocks will be styled using
react-syntax-highlighter
to ensure code examples are readable and match the site's aesthetic. - Data Fetching: We will use Node.js's
fs
andpath
modules within Next.js Server Components to read the documentation files and their directory structure from the server's file system.
2. File and Component Structure
A new app/docs/
route will be created with the following structure:
app/docs/layout.tsx
: A new layout file specific to the documentation section. It will create a two-column view with a navigation sidebar.app/docs/[...slug]/page.tsx
: A dynamic route that catches all documentation URLs. Theslug
will correspond to the path of the Markdown file being requested.components/DocsSidebar.tsx
: A new component that displays the nested navigation menu for all documentation pages.components/MarkdownRenderer.tsx
: A dedicated component to handle the rendering of Markdown content, including styled code blocks and other elements.lib/docs.ts
: A new utility file containing helper functions to scan thedocs/
directory, build a navigation tree, and retrieve individual document content.
3. Data and Rendering Flow
This diagram illustrates how a user request for a documentation page will be handled:
Loading diagram...
4. Implementation Steps
- Install Dependencies: Add
react-markdown
,remark-gfm
, andreact-syntax-highlighter
to the project. - Create Doc Utilities (
lib/docs.ts
): Implement functions to fetch the doc navigation tree and the content of a specific doc. - Build Sidebar (
components/DocsSidebar.tsx
): Create the sidebar component that fetches the doc tree and renders it as a nested list of navigation links. - Create Documentation Layout (
app/docs/layout.tsx
): Set up the two-column layout that includes the newDocsSidebar
. - Create Markdown Renderer (
components/MarkdownRenderer.tsx
): Configurereact-markdown
andreact-syntax-highlighter
. Customize the rendering of HTML elements to reuse existing UI components fromcomponents/ui/
for a consistent look. - Create Dynamic Doc Page (
app/docs/[...slug]/page.tsx
): This page will fetch the Markdown content based on the URL slug and pass it to theMarkdownRenderer
component. - Update Header: Add a "Docs" link to the main
Header
component so users can easily find the new documentation section. - Styling: Apply Tailwind CSS classes to all new components to ensure the design is consistent with the rest of the application.