Docusaurus Guide
This guide covers how to use and customize the Docusaurus documentation site in this template.
Quick Start
Prerequisites
- Node.js 18.0 or higher
- npm or yarn package manager
Installation
# Navigate to the docs folder
cd docs
# Install dependencies
npm install
# Start development server
npm run start
The site will be available at http://localhost:3000.
Build for Production
# Build the static site
npm run build
# Preview the production build
npm run serve
Project Structure
docs/
├── docs/ # Documentation content (Markdown/MDX)
│ ├── intro.md # Landing page for /docs
│ ├── guides/ # How-to guides
│ ├── reference/ # API/reference documentation
│ ├── community/ # Community guidelines
│ └── decisions/ # Architecture Decision Records
├── src/
│ ├── components/ # React components
│ ├── css/ # Custom styles
│ ├── pages/ # Custom pages (landing, etc.)
│ └── theme/ # Theme overrides
├── static/ # Static assets (images, files)
├── i18n/ # Internationalization files
├── docusaurus.config.js # Main configuration
├── sidebars.js # Sidebar navigation
└── package.json # Dependencies
Writing Documentation
Basic Markdown
Create a new .md file in the docs/ folder:
---
id: my-doc
title: My Document
sidebar_label: My Doc
sidebar_position: 1
---
# My Document
Your content here...
Front Matter Options
| Field | Description |
|---|---|
id | Unique document ID (used in URLs and links) |
title | Document title (shown in browser tab) |
sidebar_label | Short label for sidebar |
sidebar_position | Order in sidebar (lower = higher) |
description | Meta description for SEO |
keywords | SEO keywords array |
tags | Document tags for grouping |
hide_title | Hide the title heading |
hide_table_of_contents | Hide the TOC |
draft | Hide in production if true |
Linking Between Documents
<!-- Relative link (recommended) -->
[Getting Started](./GETTING_STARTED.md)
<!-- By document ID -->
[Contributing](/docs/reference/contributing)
<!-- With anchor -->
[Installation Section](./GETTING_STARTED.md#installation)
Adding Images
Place images in static/img/ and reference them:

Or use relative paths for co-located images:

MDX Features
Docusaurus supports MDX, allowing React components in Markdown.
Admonitions (Callouts)
:::note
This is a note.
:::
:::tip
Pro tip here!
:::
:::info
Informational content.
:::
:::warning
Be careful!
:::
:::danger
Critical warning!
:::
Code Blocks
```javascript title="example.js"
const greeting = 'Hello, World!';
console.log(greeting);
```
```python {2-3} showLineNumbers
def hello():
# These lines are highlighted
print("Hello, World!")
```
Tabs
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
<Tabs>
<TabItem value="npm" label="npm" default>
npm install package-name
</TabItem>
<TabItem value="yarn" label="Yarn">
yarn add package-name
</TabItem>
</Tabs>
Mermaid Diagrams
This template has Mermaid enabled. Create diagrams in Markdown:
```mermaid
graph LR
A[Start] --> B{Decision}
B -->|Yes| C[Action 1]
B -->|No| D[Action 2]
```
Sidebar Configuration
Edit sidebars.js to customize navigation:
const sidebars = {
docsSidebar: [
// Single document
{
type: 'doc',
id: 'intro',
label: '🚀 Getting Started',
},
// Category with items
{
type: 'category',
label: '📚 Guides',
collapsed: false, // Start expanded
items: [
'guides/GETTING_STARTED',
'guides/DOCUSAURUS_GUIDE',
// Nested category
{
type: 'category',
label: '⚙️ Advanced',
items: ['guides/SEARCH_GUIDE'],
},
],
},
// Auto-generated from folder
{
type: 'autogenerated',
dirName: 'reference',
},
// External link
{
type: 'link',
label: 'GitHub',
href: 'https://github.com/your-repo',
},
],
};
Configuration
docusaurus.config.js
Key configuration options:
const config = {
title: 'Your Site Title',
tagline: 'Your tagline',
url: 'https://your-domain.com',
baseUrl: '/',
// Behavior on broken links
onBrokenLinks: 'throw',
onBrokenMarkdownLinks: 'warn',
// Internationalization
i18n: {
defaultLocale: 'en',
locales: ['en', 'zh-TW'],
},
// Theme configuration
themeConfig: {
navbar: { /* ... */ },
footer: { /* ... */ },
colorMode: {
defaultMode: 'light',
respectPrefersColorScheme: true,
},
},
};
Adding Navbar Items
navbar: {
title: 'My Site',
logo: {
alt: 'Logo',
src: 'img/logo.svg',
},
items: [
// Link to docs
{
type: 'docSidebar',
sidebarId: 'docsSidebar',
label: 'Docs',
position: 'left',
},
// External link
{
href: 'https://github.com/your-repo',
label: 'GitHub',
position: 'right',
},
// Language dropdown
{
type: 'localeDropdown',
position: 'right',
},
],
},
Internationalization (i18n)
Translating Documents
-
Copy the document to the locale folder:
docs/i18n/zh-TW/docusaurus-plugin-content-docs/current/ -
Translate the content while keeping the same filename.
Translating UI Strings
Edit i18n/zh-TW/code.json:
{
"theme.common.editThisPage": {
"message": "編輯此頁",
"description": "The link label to edit the current page"
}
}
Building for All Locales
# Build all locales
npm run build
# Start dev server with specific locale
npm run start -- --locale zh-TW
Customization
Custom CSS
Edit src/css/custom.css:
:root {
--ifm-color-primary: #667eea;
--ifm-code-font-size: 95%;
}
[data-theme='dark'] {
--ifm-color-primary: #8099f4;
}