web-meta-framework-docusaurus

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Docusaurus

Docusaurus

Quick Guide: Docusaurus 3.x is a React-powered static site generator for documentation. Configure everything in
docusaurus.config.js
(ESM). Use
@docusaurus/preset-classic
for docs + blog + pages + sitemap in one preset. Sidebars can be fully autogenerated from filesystem structure using
_category_.json
and front matter
sidebar_position
. Customize theme components via swizzling (prefer
--wrap
over
--eject
). MDX is the default content format — use front matter for metadata, admonitions for callouts, and import React components directly in
.mdx
files. Version docs with
docusaurus docs:version
. Deploy the
build/
output to any static host.

<critical_requirements>
快速指南: Docusaurus 3.x 是一款基于 React 的文档静态站点生成器。所有配置均在
docusaurus.config.js
(ESM 格式)中完成。使用
@docusaurus/preset-classic
预设可一站式集成文档、博客、页面与站点地图功能。通过
_category_.json
文件和 front matter 中的
sidebar_position
字段,可完全根据文件系统结构自动生成侧边栏。通过 Swizzling 自定义主题组件时,优先使用
--wrap
而非
--eject
。MDX 是默认内容格式——可使用 front matter 添加元数据,使用 admonitions 制作提示框,还可在
.mdx
文件中直接导入 React 组件。使用
docusaurus docs:version
命令为文档添加版本管理。将
build/
目录下的输出文件部署至任意静态托管平台即可。

<critical_requirements>

CRITICAL: Before Using This Skill

重要提示:使用此技能前

All code must follow project conventions in CLAUDE.md
(You MUST use
docusaurus.config.js
(or
.ts
) as the single source of truth for all site configuration — never scatter config across multiple files)
(You MUST use
@docusaurus/preset-classic
unless you have a specific reason to configure plugins individually — the preset bundles docs, blog, pages, sitemap, and theme)
(You MUST prefer
--wrap
over
--eject
when swizzling — wrapping preserves upstream updates, ejecting creates a maintenance burden)
(You MUST use front matter
sidebar_position
and
_category_.json
for sidebar ordering in autogenerated sidebars — do not fight the filesystem-driven convention)
(You MUST NOT mix versioned and unversioned docs in the same plugin instance — use separate plugin instances for different doc sets)
</critical_requirements>

Auto-detection: Docusaurus, docusaurus.config.js, docusaurus.config.ts, @docusaurus/preset-classic, @docusaurus/core, sidebars.js, docs:version, docusaurus build, docusaurus start, docusaurus deploy, docusaurus swizzle, MDX, category.json, sidebar_position, @site, @theme, @theme-original, plugin-content-docs, plugin-content-blog
When to use:
  • Configuring
    docusaurus.config.js
    (site metadata, presets, plugins, theme, navbar, footer)
  • Setting up or modifying sidebar structure (autogenerated or manual)
  • Adding versioned documentation
  • Customizing theme components via swizzling
  • Writing MDX content with Docusaurus-specific features (admonitions, tabs, code blocks)
  • Creating custom pages with React components
  • Configuring the blog plugin
  • Setting up search (Algolia DocSearch or local)
  • Deploying Docusaurus to static hosting
  • Configuring i18n / localization
When NOT to use:
  • General React component patterns (Docusaurus uses React internally but this skill covers Docusaurus APIs, not React fundamentals)
  • CSS/styling approaches not specific to Docusaurus theming (general CSS patterns are a separate concern)
  • Git hooks, linting, or formatting setup (separate from documentation framework concerns)
  • Content that belongs in the docs themselves, not the site framework
  • VitePress — Vue-based, different config format and plugin system
  • Nextra — Next.js-based, uses
    _meta.json
    not
    _category_.json
    , different routing model
  • Starlight — Astro-based, uses
    astro.config.mjs
    and content collections, different architecture entirely

所有代码必须遵循 CLAUDE.md 中的项目约定
(必须将
docusaurus.config.js
(或
.ts
)作为所有站点配置的唯一可信来源——切勿将配置分散到多个文件中)
(必须使用
@docusaurus/preset-classic
,除非有特殊原因需要单独配置插件——该预设集成了文档、博客、页面、站点地图及主题功能)
(进行 Swizzling 时必须优先使用
--wrap
而非
--eject
——包装模式可保留上游更新,而导出模式会增加维护负担)
(必须使用 front matter 中的
sidebar_position
和
_category_.json
来配置自动生成侧边栏的排序——不要违背文件系统驱动的约定)
(不得在同一个插件实例中混合使用版本化和非版本化文档——为不同的文档集使用单独的插件实例)
</critical_requirements>

自动检测项: Docusaurus, docusaurus.config.js, docusaurus.config.ts, @docusaurus/preset-classic, @docusaurus/core, sidebars.js, docs:version, docusaurus build, docusaurus start, docusaurus deploy, docusaurus swizzle, MDX, category.json, sidebar_position, @site, @theme, @theme-original, plugin-content-docs, plugin-content-blog
适用场景:
  • 配置
    docusaurus.config.js
    (站点元数据、预设、插件、主题、导航栏、页脚)
  • 设置或修改侧边栏结构(自动生成或手动配置)
  • 添加版本化文档
  • 通过 Swizzling 自定义主题组件
  • 使用 Docusaurus 专属特性编写 MDX 内容(提示框、标签页、代码块)
  • 使用 React 组件创建自定义页面
  • 配置博客插件
  • 设置搜索功能(Algolia DocSearch 或本地搜索)
  • 将 Docusaurus 部署到静态托管平台
  • 配置国际化/本地化
不适用场景:
  • 通用 React 组件模式(Docusaurus 内部使用 React,但本技能仅覆盖 Docusaurus API,不涉及 React 基础知识)
  • 非 Docusaurus 主题专属的 CSS/样式方案(通用 CSS 模式属于独立范畴)
  • Git 钩子、代码检查或格式化设置(与文档框架无关)
  • 应放在文档内容中的内容,而非站点框架配置
  • VitePress——基于 Vue,配置格式和插件系统不同
  • Nextra——基于 Next.js,使用
    _meta.json
    而非
    _category_.json
    ,路由模型不同
  • Starlight——基于 Astro,使用
    astro.config.mjs
    和内容集合,架构完全不同

Examples

示例

  • Core Configuration & Sidebars — docusaurus.config.js, preset-classic, sidebars, front matter, custom pages
  • MDX & Content — MDX features, admonitions, tabs, code blocks, assets, blog plugin
  • Customization & Deployment — Swizzling, CSS variables, versioning, i18n, search, deployment
Other resources:
  • Quick Reference — CLI commands, front matter fields, config option tables

<philosophy>
  • 核心配置与侧边栏 —— docusaurus.config.js、preset-classic、侧边栏、front matter、自定义页面
  • MDX 与内容 —— MDX 特性、提示框、标签页、代码块、资源、博客插件
  • 定制与部署 —— Swizzling、CSS 变量、版本管理、国际化、搜索、部署
其他资源:
  • 快速参考 —— CLI 命令、front matter 字段、配置选项表

<philosophy>

Philosophy

设计理念

Docusaurus is an opinionated documentation framework that trades flexibility for convention. It makes strong decisions about routing (filesystem-based), content format (MDX), and structure (docs + blog + pages) so you can focus on writing content rather than building infrastructure.
Core principles:
  1. Convention over configuration — filesystem structure drives routing and sidebar generation; fight this and you fight the framework
  2. Preset-first —
    preset-classic
    bundles the common plugin set; only decompose into individual plugins when you need multiple docs instances or unusual setups
  3. Content as data — front matter is the metadata layer;
    sidebar_position
    ,
    slug
    ,
    tags
    ,
    custom_edit_url
    all live in the document, not in external config
  4. Swizzle, don't fork — customize theme components via the swizzle CLI; wrapping preserves upstream compatibility, ejecting creates a snapshot you must maintain
  5. Static output —
    docusaurus build
    produces a static site; there is no server runtime, no SSR in production, no API routes
</philosophy>
<patterns>
Docusaurus 是一款** Opinionated(约定优先)的文档框架**,以灵活性换取约定一致性。它在路由(基于文件系统)、内容格式(MDX)和结构(文档+博客+页面)方面做出了明确决策,让你可以专注于内容创作而非基础设施搭建。
核心原则:
  1. 约定优于配置——文件系统结构决定路由和侧边栏生成;违背这一点就是与框架作对
  2. 预设优先——
    preset-classic
    集成了常用插件集;仅在需要多个文档实例或特殊配置时才拆分为单独插件
  3. 内容即数据——front matter 是元数据层;
    sidebar_position
    、
    slug
    、
    tags
    、
    custom_edit_url
    均存储在文档中,而非外部配置
  4. Swizzle 而非 Fork——通过 Swizzle CLI 自定义主题组件;包装模式保留上游兼容性,导出模式会生成一个需要你自行维护的快照
  5. 静态输出——
    docusaurus build
    生成静态站点;生产环境无服务器运行时、无 SSR、无 API 路由
</philosophy>
<patterns>

Core Patterns

核心模式

Pattern 1: docusaurus.config.js Structure

模式 1:docusaurus.config.js 结构

The config file is the single entry point. It uses ESM (
export default
) and configures site metadata, presets (which bundle plugins + theme), and theme-level settings like navbar and footer.
javascript
// docusaurus.config.js — minimal production setup
export default {
  title: "My Docs",
  tagline: "Documentation for My Project",
  url: "https://docs.example.com",
  baseUrl: "/",
  onBrokenLinks: "throw",
  onBrokenMarkdownLinks: "throw",
  favicon: "img/favicon.ico",

  presets: [
    [
      "@docusaurus/preset-classic",
      {
        docs: {
          sidebarPath: "./sidebars.js",
          editUrl: "https://github.com/my-org/my-repo/edit/main/docs-site/",
          showLastUpdateTime: true,
        },
        blog: { showReadingTime: true },
        theme: { customCss: ["./src/css/custom.css"] },
      },
    ],
  ],

  themeConfig: {
    navbar: {
      title: "My Docs",
      items: [
        /* nav items */
      ],
    },
    footer: {
      style: "dark",
      links: [
        /* footer columns */
      ],
    },
    docs: { sidebar: { hideable: true, autoCollapseCategories: true } },
  },
};
Key gotcha:
onBrokenLinks: 'throw'
is essential for production — it fails the build on broken internal links rather than silently deploying dead links.
Full example: See examples/core.md for complete config with navbar, footer, and multi-instance docs setup.

配置文件是唯一入口点。它使用 ESM(
export default
)格式,配置站点元数据、预设(集成插件+主题)以及导航栏、页脚等主题级设置。
javascript
// docusaurus.config.js —— 最小化生产环境配置
export default {
  title: "My Docs",
  tagline: "Documentation for My Project",
  url: "https://docs.example.com",
  baseUrl: "/",
  onBrokenLinks: "throw",
  onBrokenMarkdownLinks: "throw",
  favicon: "img/favicon.ico",

  presets: [
    [
      "@docusaurus/preset-classic",
      {
        docs: {
          sidebarPath: "./sidebars.js",
          editUrl: "https://github.com/my-org/my-repo/edit/main/docs-site/",
          showLastUpdateTime: true,
        },
        blog: { showReadingTime: true },
        theme: { customCss: ["./src/css/custom.css"] },
      },
    ],
  ],

  themeConfig: {
    navbar: {
      title: "My Docs",
      items: [
        /* 导航项 */
      ],
    },
    footer: {
      style: "dark",
      links: [
        /* 页脚列 */
      ],
    },
    docs: { sidebar: { hideable: true, autoCollapseCategories: true } },
  },
};
关键注意事项:
onBrokenLinks: 'throw'
对生产环境至关重要——它会在存在无效内部链接时终止构建,而非静默部署死链接。
完整示例: 查看 examples/core.md 获取包含导航栏、页脚和多实例文档设置的完整配置。

Pattern 2: Sidebar Configuration

模式 2:侧边栏配置

Docusaurus offers two sidebar strategies. Autogenerated sidebars derive structure from the filesystem and are the default recommendation. Manual sidebars give full control but require maintenance.
javascript
// sidebars.js — autogenerated (recommended)
export default {
  docs: [{ type: "autogenerated", dirName: "." }],
};
Control ordering and labels via front matter and
_category_.json
:
markdown
---
sidebar_position: 3
sidebar_label: Quick Start
---
json
// docs/guides/_category_.json
{
  "label": "Guides",
  "position": 2,
  "collapsible": true,
  "collapsed": false,
  "link": { "type": "generated-index", "title": "All Guides" }
}
Key gotcha: Without
sidebar_position
, items sort alphabetically by filename. Use number prefixes (
01-intro.md
) or front matter — but not both, as number prefixes are stripped from the URL slug.
Full example: See examples/core.md for manual sidebars, custom sidebar items generator, and multi-sidebar setups.

Docusaurus 提供两种侧边栏策略。自动生成侧边栏从文件系统派生结构,是推荐的默认方案。手动侧边栏提供完全控制权,但需要维护。
javascript
// sidebars.js —— 自动生成(推荐)
export default {
  docs: [{ type: "autogenerated", dirName: "." }],
};
通过 front matter 和
_category_.json
控制排序和标签:
markdown
---
sidebar_position: 3
sidebar_label: 快速开始
---
json
// docs/guides/_category_.json
{
  "label": "指南",
  "position": 2,
  "collapsible": true,
  "collapsed": false,
  "link": { "type": "generated-index", "title": "所有指南" }
}
关键注意事项: 如果没有
sidebar_position
,项会按文件名字母顺序排序。可使用数字前缀(
01-intro.md
)或 front matter——但不要同时使用,因为数字前缀会从 URL 路径中移除。
完整示例: 查看 examples/core.md 获取手动侧边栏、自定义侧边栏项生成器和多侧边栏设置。

Pattern 3: Swizzling Theme Components

模式 3:Swizzling 主题组件

Swizzling lets you customize any theme component. Wrapping adds behavior around the original; ejecting gives you a full copy to modify.
bash
undefined
Swizzling 允许你自定义任何主题组件。包装模式在原始组件周围添加行为;导出模式提供完整副本供你修改。
bash
undefined

List all swizzlable components

列出所有可 Swizzle 的组件

npx docusaurus swizzle --list
npx docusaurus swizzle --list

Wrap a component (SAFE — preserves upstream updates)

包装组件(安全——保留上游更新)

npx docusaurus swizzle @docusaurus/theme-classic Footer -- --wrap
npx docusaurus swizzle @docusaurus/theme-classic Footer -- --wrap

Eject a component (DANGEROUS — you own the snapshot)

导出组件(危险——你需维护快照)

npx docusaurus swizzle @docusaurus/theme-classic Footer -- --eject

```jsx
// src/theme/Footer/index.js — wrapping example
import React from "react";
import Footer from "@theme-original/Footer";

export default function FooterWrapper(props) {
  return (
    <>
      <Footer {...props} />
      <div className="custom-banner">Custom content below footer</div>
    </>
  );
}
Key gotcha: The
@theme-original/
import is critical in wrappers — it references the original component. Using
@theme/
would create an infinite loop since your wrapper IS the
@theme/Footer
.
Full example: See examples/customization.md for swizzling safety levels, common swizzle targets, and CSS variable theming.

npx docusaurus swizzle @docusaurus/theme-classic Footer -- --eject

```jsx
// src/theme/Footer/index.js —— 包装示例
import React from "react";
import Footer from "@theme-original/Footer";

export default function FooterWrapper(props) {
  return (
    <>
      <Footer {...props} />
      <div className="custom-banner">页脚下方的自定义内容</div>
    </>
  );
}
关键注意事项: 在包装组件中,
@theme-original/
导入至关重要——它引用原始组件。使用
@theme/
会创建无限循环,因为你的包装组件就是
@theme/Footer
。
完整示例: 查看 examples/customization.md 获取 Swizzle 安全级别、常见 Swizzle 目标和 CSS 变量主题设置。

Pattern 4: MDX Content Features

模式 4:MDX 内容特性

Docusaurus uses MDX v3 — Markdown with embedded JSX. Key Docusaurus-specific features include admonitions, tabs, and code blocks with metadata.
mdx
---
title: My Document
description: SEO description for this page
sidebar_position: 1
tags: [getting-started, tutorial]
---

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

:::tip[Pro Tip]
Admonitions support `note`, `tip`, `info`, `warning`, `danger` types.
The bracket syntax `:::tip[Custom Title]` sets the title.
:::

<Tabs>
  <TabItem value="npm" label="npm" default>
    ```bash npm install my-package ```
  </TabItem>
  <TabItem value="yarn" label="yarn">
    ```bash yarn add my-package ```
  </TabItem>
</Tabs>
Key gotcha: MDX v3 is stricter than Markdown — unclosed HTML tags, bare
{
characters, and
<
comparisons in text will cause build errors. Escape them with
\{
and
\<
or use code fences.
Full example: See examples/content.md for code block features, asset handling, and blog plugin configuration.

Docusaurus 使用 MDX v3——嵌入 JSX 的 Markdown。Docusaurus 专属的关键特性包括提示框、标签页和带元数据的代码块。
mdx
---
title: 我的文档
description: 此页面的 SEO 描述
sidebar_position: 1
tags: [入门, 教程]
---

import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";

:::tip[专业提示]
提示框支持 `note`、`tip`、`info`、`warning`、`danger` 类型。
使用括号语法 `:::tip[自定义标题]` 设置标题。
:::

<Tabs>
  <TabItem value="npm" label="npm" default>
    ```bash npm install my-package ```
  </TabItem>
  <TabItem value="yarn" label="yarn">
    ```bash yarn add my-package ```
  </TabItem>
</Tabs>
关键注意事项: MDX v3 比 Markdown 更严格——未闭合的 HTML 标签、裸
{
字符和文本中的
<
比较会导致构建错误。使用
\{
和
\<
转义,或放在代码块中。
完整示例: 查看 examples/content.md 获取代码块特性、资源处理和博客插件配置。

Pattern 5: Versioning

模式 5:版本管理

Docusaurus versions docs by snapshotting the entire
docs/
directory. The current working copy is always
current
(next/unreleased). Cut a release version when shipping.
bash
undefined
Docusaurus 通过快照整个
docs/
目录来为文档添加版本。当前工作副本始终是
current
(下一版本/未发布)。发布时创建一个版本快照。
bash
undefined

Snapshot current docs as version 1.0.0

将当前文档快照为版本 1.0.0

npx docusaurus docs:version 1.0.0

This creates `versioned_docs/version-1.0.0/` and `versioned_sidebars/version-1.0.0-sidebars.json`. Configure version behavior in the docs plugin:

```javascript
// In preset-classic docs options
docs: {
  lastVersion: 'current',
  versions: {
    current: { label: '2.0.0-beta', path: 'next', banner: 'unreleased' },
    '1.0.0': { label: '1.0.0', path: '1.0.0', banner: 'none' },
  },
  onlyIncludeVersions: ['current', '1.0.0'],
}
Key gotcha: Versioned docs are full copies, not diffs. Each version doubles the build time and output size. Use
onlyIncludeVersions
in development to speed up builds. Only version when you have actual API/feature differences — not for every release.
Full example: See examples/customization.md for version banner configuration and multi-version navigation.
</patterns>
<decision_framework>
npx docusaurus docs:version 1.0.0

这会创建 `versioned_docs/version-1.0.0/` 和 `versioned_sidebars/version-1.0.0-sidebars.json`。在文档插件中配置版本行为:

```javascript
// 在 preset-classic 的 docs 选项中
docs: {
  lastVersion: 'current',
  versions: {
    current: { label: '2.0.0-beta', path: 'next', banner: 'unreleased' },
    '1.0.0': { label: '1.0.0', path: '1.0.0', banner: 'none' },
  },
  onlyIncludeVersions: ['current', '1.0.0'],
}
关键注意事项: 版本化文档是完整副本,而非差异文件。每个版本都会使构建时间和输出大小翻倍。在开发环境中使用
onlyIncludeVersions
加快构建速度。仅当存在实际 API/功能差异时才进行版本管理——不要为每个版本都做。
完整示例: 查看 examples/customization.md 获取版本横幅配置和多版本导航。
</patterns>
<decision_framework>

Decision Framework

决策框架

Sidebar Strategy

侧边栏策略

How should the sidebar be organized?
|-- Small docs site (< 30 pages)?
|   +-- Use autogenerated sidebar with sidebar_position front matter
|-- Large docs site with many sections?
|   |-- Sections map cleanly to directories? -> Autogenerated + _category_.json
|   +-- Need cross-directory grouping? -> Manual sidebar in sidebars.js
|-- Multiple independent doc sets (e.g., API + guides)?
|   +-- Use multiple docs plugin instances, each with its own sidebar
+-- Need to mix auto and manual?
    +-- Use autogenerated for most, with manual items for special entries
如何组织侧边栏?
|-- 小型文档站点(<30 页)?
|   +-- 使用带 sidebar_position front matter 的自动生成侧边栏
|-- 大型文档站点,包含多个章节?
|   |-- 章节与目录清晰对应? -> 自动生成 + _category_.json
|   +-- 需要跨目录分组? -> 在 sidebars.js 中手动配置侧边栏
|-- 多个独立文档集(如 API + 指南)?
|   +-- 使用多个文档插件实例,每个实例有自己的侧边栏
+-- 需要混合自动和手动配置?
    +-- 大部分使用自动生成,为特殊条目添加手动项

Swizzling Approach

Swizzling 方案

Need to customize a theme component?
|-- Adding content around the component? -> Wrap (--wrap)
|-- Need to change the component's internal logic? -> Check safety level first
|   |-- Component marked "Safe"? -> Eject is acceptable
|   |-- Component marked "Unsafe"? -> Wrap if possible, eject only as last resort
|   +-- Component marked "Forbidden"? -> Do not swizzle — find another approach
+-- Just changing colors/spacing? -> Use CSS variables in custom.css (no swizzle needed)
需要自定义主题组件?
|-- 在组件周围添加内容? -> 使用包装模式(--wrap)
|-- 需要修改组件内部逻辑? -> 先检查安全级别
|   |-- 组件标记为“Safe”? -> 可以使用导出模式
|   |-- 组件标记为“Unsafe”? -> 尽可能使用包装模式,仅在万不得已时使用导出模式
|   +-- 组件标记为“Forbidden”? -> 不要进行 Swizzle——寻找其他方案
+-- 仅更改颜色/间距? -> 在 custom.css 中使用 CSS 变量(无需 Swizzle)

Content Format

内容格式

What kind of page am I creating?
|-- Documentation article? -> .md or .mdx file in docs/
|-- Blog post? -> .md or .mdx file in blog/
|-- Standalone page with custom layout?
|   |-- Mostly content? -> .mdx in src/pages/
|   +-- Mostly interactive/React? -> .tsx in src/pages/
+-- Need to embed React components in docs? -> Use .mdx with imports
</decision_framework>

<red_flags>
我要创建哪种页面?
|-- 文档文章? -> docs/ 目录下的 .md 或 .mdx 文件
|-- 博客文章? -> blog/ 目录下的 .md 或 .mdx 文件
|-- 带自定义布局的独立页面?
|   |-- 以内容为主? -> src/pages/ 目录下的 .mdx 文件
|   +-- 以交互/React 为主? -> src/pages/ 目录下的 .tsx 文件
+-- 需要在文档中嵌入 React 组件? -> 使用带导入语句的 .mdx 文件
</decision_framework>

<red_flags>

RED FLAGS

警示事项

High Priority Issues:
  • Using
    onBrokenLinks: 'ignore'
    or
    'log'
    in production — broken links should fail the build (
    'throw'
    )
  • Ejecting theme components when wrapping would suffice — ejected components miss upstream bug fixes and feature additions
  • Using
    @theme/ComponentName
    import in a swizzle wrapper instead of
    @theme-original/ComponentName
    — creates an infinite import loop
  • Putting all sidebar config in
    sidebars.js
    manually when autogenerated would work — creates a maintenance burden that falls out of sync with actual docs
Medium Priority Issues:
  • Versioning every release instead of only when docs content actually changes — bloats build time and output size
  • Not setting
    onBrokenMarkdownLinks: 'warn'
    at minimum — silent broken links accumulate
  • Missing
    editUrl
    in docs plugin config — blocks "Edit this page" links that drive community contributions
  • Not using
    showLastUpdateTime: true
    — readers cannot tell how current a doc page is
Common Mistakes:
  • Bare
    {
    or
    <
    in MDX content causing build failures — escape with
    \{
    and
    \<
    or wrap in code fences
  • Forgetting to restart the dev server after changing
    docusaurus.config.js
    — config changes are not hot-reloaded
  • Using
    .md
    extension with JSX when
    format: 'detect'
    is configured — in detect mode, only
    .mdx
    files support JSX (default mode processes both)
  • Creating
    _category_.json
    with wrong field names (
    name
    instead of
    label
    ,
    order
    instead of
    position
    )
  • Importing from
    @docusaurus/
    packages directly in MDX — use
    @theme/
    or
    @site/
    aliases instead
Gotchas & Edge Cases:
  • baseUrl
    must end with
    /
    — omitting the trailing slash breaks asset resolution
  • Static assets in
    static/
    are served from root, not from
    baseUrl
    — use
    require()
    or
    useBaseUrl()
    for path-safe references
  • Blog authors are configured in
    blog/authors.yml
    , not in
    docusaurus.config.js
  • The
    slug
    front matter field overrides the URL path derived from the filename — useful for keeping clean URLs when renaming files
  • docs-only mode
    requires setting
    routeBasePath: '/'
    in the docs plugin AND
    blog: false
    in the preset
  • Custom pages in
    src/pages/
    use the file path as the route —
    src/pages/support.tsx
    becomes
    /support
  • Tabs component state is not shared between instances by default — use
    groupId
    prop to sync tab selection across the page
</red_flags>

<critical_reminders>
高优先级问题:
  • 在生产环境中使用
    onBrokenLinks: 'ignore'
    或
    'log'
    ——无效链接应终止构建(
    'throw'
    )
  • 当包装模式足够时却导出主题组件——导出的组件会错过上游 bug 修复和功能更新
  • 在 Swizzle 包装组件中使用
    @theme/ComponentName
    导入而非
    @theme-original/ComponentName
    ——会创建无限导入循环
  • 当自动生成方案可行时,却在
    sidebars.js
    中手动配置所有侧边栏——会产生与实际文档不同步的维护负担
中优先级问题:
  • 每次发布都进行版本管理,而非仅在文档内容实际变化时——会增加构建时间和输出大小
  • 未设置
    onBrokenMarkdownLinks: 'warn'
    及以上级别——无效链接会悄悄累积
  • 文档插件配置中缺少
    editUrl
    ——会阻止驱动社区贡献的“编辑此页面”链接
  • 未启用
    showLastUpdateTime: true
    ——读者无法判断文档页面的时效性
常见错误:
  • MDX 内容中的裸
    {
    或
    <
    导致构建失败——使用
    \{
    和
    \<
    转义,或放在代码块中
  • 修改
    docusaurus.config.js
    后忘记重启开发服务器——配置更改不会热加载
  • 在配置
    format: 'detect'
    时,使用
    .md
    扩展名包含 JSX——在检测模式下,只有
    .mdx
    文件支持 JSX(默认模式处理两者)
  • 创建的
    _category_.json
    字段名错误(用
    name
    代替
    label
    ,用
    order
    代替
    position
    )
  • 在 MDX 中直接从
    @docusaurus/
    包导入——改用
    @theme/
    或
    @site/
    别名
注意事项与边缘情况:
  • baseUrl
    必须以
    /
    结尾——省略尾部斜杠会破坏资源解析
  • static/
    中的静态资源从根目录提供,而非从
    baseUrl
    ——使用
    require()
    或
    useBaseUrl()
    获取路径安全的引用
  • 博客作者在
    blog/authors.yml
    中配置,而非
    docusaurus.config.js
  • front matter 中的
    slug
    字段会覆盖从文件名派生的 URL 路径——重命名文件时可用于保持清晰的 URL
  • 仅文档模式需要在文档插件中设置
    routeBasePath: '/'
    并在预设中设置
    blog: false
  • src/pages/
    中的自定义页面使用文件路径作为路由——
    src/pages/support.tsx
    会变为
    /support
  • 默认情况下,标签页组件状态在实例之间不共享——使用
    groupId
    属性同步页面中的标签选择
</red_flags>

<critical_reminders>

CRITICAL REMINDERS

重要提醒

All code must follow project conventions in CLAUDE.md
(You MUST use
docusaurus.config.js
as the single source of truth for all site configuration)
(You MUST use
@docusaurus/preset-classic
unless you have a specific reason to configure plugins individually)
(You MUST prefer
--wrap
over
--eject
when swizzling — wrapping preserves upstream updates)
(You MUST use front matter
sidebar_position
and
_category_.json
for sidebar ordering — do not fight filesystem-driven conventions)
(You MUST NOT mix versioned and unversioned docs in the same plugin instance)
Failure to follow these rules will cause broken builds, unmaintainable theme overrides, and sidebar chaos.
</critical_reminders>
所有代码必须遵循 CLAUDE.md 中的项目约定
(必须将
docusaurus.config.js
作为所有站点配置的唯一可信来源)
(必须使用
@docusaurus/preset-classic
,除非有特殊原因需要单独配置插件)
(进行 Swizzling 时必须优先使用
--wrap
而非
--eject
——包装模式可保留上游更新)
(必须使用 front matter 中的
sidebar_position
和
_category_.json
配置侧边栏排序——不要违背文件系统驱动的约定)
(不得在同一个插件实例中混合使用版本化和非版本化文档)
不遵守这些规则会导致构建失败、主题覆盖难以维护以及侧边栏混乱。
</critical_reminders>