web-meta-framework-docusaurus
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDocusaurus
Docusaurus
Quick Guide: Docusaurus 3.x is a React-powered static site generator for documentation. Configure everything in(ESM). Usedocusaurus.config.jsfor docs + blog + pages + sitemap in one preset. Sidebars can be fully autogenerated from filesystem structure using@docusaurus/preset-classicand front matter_category_.json. Customize theme components via swizzling (prefersidebar_positionover--wrap). MDX is the default content format — use front matter for metadata, admonitions for callouts, and import React components directly in--ejectfiles. Version docs with.mdx. Deploy thedocusaurus docs:versionoutput to any static host.build/
<critical_requirements>
快速指南: Docusaurus 3.x 是一款基于 React 的文档静态站点生成器。所有配置均在(ESM 格式)中完成。使用docusaurus.config.js预设可一站式集成文档、博客、页面与站点地图功能。通过@docusaurus/preset-classic文件和 front matter 中的_category_.json字段,可完全根据文件系统结构自动生成侧边栏。通过 Swizzling 自定义主题组件时,优先使用sidebar_position而非--wrap。MDX 是默认内容格式——可使用 front matter 添加元数据,使用 admonitions 制作提示框,还可在--eject文件中直接导入 React 组件。使用.mdx命令为文档添加版本管理。将docusaurus docs:version目录下的输出文件部署至任意静态托管平台即可。build/
<critical_requirements>
CRITICAL: Before Using This Skill
重要提示:使用此技能前
All code must follow project conventions in CLAUDE.md
(You MUST use (or ) as the single source of truth for all site configuration — never scatter config across multiple files)
docusaurus.config.js.ts(You MUST use unless you have a specific reason to configure plugins individually — the preset bundles docs, blog, pages, sitemap, and theme)
@docusaurus/preset-classic(You MUST prefer over when swizzling — wrapping preserves upstream updates, ejecting creates a maintenance burden)
--wrap--eject(You MUST use front matter and for sidebar ordering in autogenerated sidebars — do not fight the filesystem-driven convention)
sidebar_position_category_.json(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 (site metadata, presets, plugins, theme, navbar, footer)
docusaurus.config.js - 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 not
_meta.json, different routing model_category_.json - Starlight — Astro-based, uses and content collections, different architecture entirely
astro.config.mjs
所有代码必须遵循 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:
- Convention over configuration — filesystem structure drives routing and sidebar generation; fight this and you fight the framework
- Preset-first — bundles the common plugin set; only decompose into individual plugins when you need multiple docs instances or unusual setups
preset-classic - Content as data — front matter is the metadata layer; ,
sidebar_position,slug,tagsall live in the document, not in external configcustom_edit_url - Swizzle, don't fork — customize theme components via the swizzle CLI; wrapping preserves upstream compatibility, ejecting creates a snapshot you must maintain
- Static output — produces a static site; there is no server runtime, no SSR in production, no API routes
docusaurus build
<patterns>
Docusaurus 是一款** Opinionated(约定优先)的文档框架**,以灵活性换取约定一致性。它在路由(基于文件系统)、内容格式(MDX)和结构(文档+博客+页面)方面做出了明确决策,让你可以专注于内容创作而非基础设施搭建。
核心原则:
- 约定优于配置——文件系统结构决定路由和侧边栏生成;违背这一点就是与框架作对
- 预设优先——集成了常用插件集;仅在需要多个文档实例或特殊配置时才拆分为单独插件
preset-classic - 内容即数据——front matter 是元数据层;、
sidebar_position、slug、tags均存储在文档中,而非外部配置custom_edit_url - Swizzle 而非 Fork——通过 Swizzle CLI 自定义主题组件;包装模式保留上游兼容性,导出模式会生成一个需要你自行维护的快照
- 静态输出——生成静态站点;生产环境无服务器运行时、无 SSR、无 API 路由
docusaurus build
<patterns>
Core Patterns
核心模式
Pattern 1: docusaurus.config.js Structure
模式 1:docusaurus.config.js 结构
The config file is the single entry point. It uses ESM () and configures site metadata, presets (which bundle plugins + theme), and theme-level settings like navbar and footer.
export defaultjavascript
// 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: is essential for production — it fails the build on broken internal links rather than silently deploying dead links.
onBrokenLinks: 'throw'Full example: See examples/core.md for complete config with navbar, footer, and multi-instance docs setup.
配置文件是唯一入口点。它使用 ESM()格式,配置站点元数据、预设(集成插件+主题)以及导航栏、页脚等主题级设置。
export defaultjavascript
// 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_.jsonmarkdown
---
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 , items sort alphabetically by filename. Use number prefixes () or front matter — but not both, as number prefixes are stripped from the URL slug.
sidebar_position01-intro.mdFull 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_.jsonmarkdown
---
sidebar_position: 3
sidebar_label: 快速开始
---json
// docs/guides/_category_.json
{
"label": "指南",
"position": 2,
"collapsible": true,
"collapsed": false,
"link": { "type": "generated-index", "title": "所有指南" }
}关键注意事项: 如果没有 ,项会按文件名字母顺序排序。可使用数字前缀()或 front matter——但不要同时使用,因为数字前缀会从 URL 路径中移除。
sidebar_position01-intro.md完整示例: 查看 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
undefinedSwizzling 允许你自定义任何主题组件。包装模式在原始组件周围添加行为;导出模式提供完整副本供你修改。
bash
undefinedList 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 import is critical in wrappers — it references the original component. Using would create an infinite loop since your wrapper IS the .
@theme-original/@theme/@theme/FooterFull 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 directory. The current working copy is always (next/unreleased). Cut a release version when shipping.
docs/currentbash
undefinedDocusaurus 通过快照整个 目录来为文档添加版本。当前工作副本始终是 (下一版本/未发布)。发布时创建一个版本快照。
docs/currentbash
undefinedSnapshot 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 in development to speed up builds. Only version when you have actual API/feature differences — not for every release.
onlyIncludeVersions</patterns>Full example: See examples/customization.md for version banner configuration and multi-version navigation.
<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'],
}关键注意事项: 版本化文档是完整副本,而非差异文件。每个版本都会使构建时间和输出大小翻倍。在开发环境中使用 加快构建速度。仅当存在实际 API/功能差异时才进行版本管理——不要为每个版本都做。
onlyIncludeVersions</patterns>完整示例: 查看 examples/customization.md 获取版本横幅配置和多版本导航。
<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 or
onBrokenLinks: 'ignore'in production — broken links should fail the build ('log')'throw' - Ejecting theme components when wrapping would suffice — ejected components miss upstream bug fixes and feature additions
- Using import in a swizzle wrapper instead of
@theme/ComponentName— creates an infinite import loop@theme-original/ComponentName - Putting all sidebar config in manually when autogenerated would work — creates a maintenance burden that falls out of sync with actual docs
sidebars.js
Medium Priority Issues:
- Versioning every release instead of only when docs content actually changes — bloats build time and output size
- Not setting at minimum — silent broken links accumulate
onBrokenMarkdownLinks: 'warn' - Missing in docs plugin config — blocks "Edit this page" links that drive community contributions
editUrl - Not using — readers cannot tell how current a doc page is
showLastUpdateTime: true
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 — config changes are not hot-reloaded
docusaurus.config.js - Using extension with JSX when
.mdis configured — in detect mode, onlyformat: 'detect'files support JSX (default mode processes both).mdx - Creating with wrong field names (
_category_.jsoninstead ofname,labelinstead oforder)position - Importing from packages directly in MDX — use
@docusaurus/or@theme/aliases instead@site/
Gotchas & Edge Cases:
- must end with
baseUrl— omitting the trailing slash breaks asset resolution/ - Static assets in are served from root, not from
static/— usebaseUrlorrequire()for path-safe referencesuseBaseUrl() - Blog authors are configured in , not in
blog/authors.ymldocusaurus.config.js - The front matter field overrides the URL path derived from the filename — useful for keeping clean URLs when renaming files
slug - requires setting
docs-only modein the docs plugin ANDrouteBasePath: '/'in the presetblog: false - Custom pages in use the file path as the route —
src/pages/becomessrc/pages/support.tsx/support - Tabs component state is not shared between instances by default — use prop to sync tab selection across the page
groupId
</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'扩展名包含 JSX——在检测模式下,只有.md文件支持 JSX(默认模式处理两者).mdx - 创建的 字段名错误(用
_category_.json代替name,用label代替order)position - 在 MDX 中直接从 包导入——改用
@docusaurus/或@theme/别名@site/
注意事项与边缘情况:
- 必须以
baseUrl结尾——省略尾部斜杠会破坏资源解析/ - 中的静态资源从根目录提供,而非从
static/——使用baseUrl或require()获取路径安全的引用useBaseUrl() - 博客作者在 中配置,而非
blog/authors.ymldocusaurus.config.js - front matter 中的 字段会覆盖从文件名派生的 URL 路径——重命名文件时可用于保持清晰的 URL
slug - 仅文档模式需要在文档插件中设置 并在预设中设置
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 as the single source of truth for all site configuration)
docusaurus.config.js(You MUST use unless you have a specific reason to configure plugins individually)
@docusaurus/preset-classic(You MUST prefer over when swizzling — wrapping preserves upstream updates)
--wrap--eject(You MUST use front matter and for sidebar ordering — do not fight filesystem-driven conventions)
sidebar_position_category_.json(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>