文档部署
TGOSKits 的文档站点基于 Docusaurus 3 构建,通过 GitHub Actions 自动部署到 GitHub Pages。本 文档介绍文档站点的架构、本地开发、写作规范和部署流程。
1. 技术栈
| 组件 | 版本 | 用途 |
|---|---|---|
| Docusaurus | 3.10+ | 静态站点生成器 |
| MDX | 3.0 | Markdown + JSX(支持在文档中使用组件) |
| Mermaid | — | 流程图 / 架构图渲染(@docusaurus/theme-mermaid) |
| prism-react-renderer | 2.x | 代码高亮 |
| Node.js | 20 | 运行时 |
| Yarn | — | 包管理(Corepack) |
2. 目录结构
docs/
├── docusaurus.config.js # 站点主 配置
├── sidebars.docs.js # 主文档 sidebar(自动生成)
├── sidebars.community.js # 社区文档 sidebar(自动生成)
├── package.json # 依赖和脚本
├── yarn.lock # 依赖锁定
├── docs/ # 主文档内容
│ ├── introduction/ # 项目介绍
│ ├── quickstart/ # 快速开始
│ ├── architecture/ # 架构设计
│ ├── build/ # 构建与运行
│ ├── contributing/ # 贡献
│ ├── development/ # 开发指南
│ ├── components/ # 组件库
│ └── debug/ # 在线调试
├── blog/ # 博客文章
│ └── 2026/
│ └── 04-10-introducing-tgoskits/
│ └── introducing-tgoskits.md
├── community/ # 社区文档(独立 sidebar)
│ ├── introduction.md
│ ├── resources.md
│ └── support.md
├── src/ # 自定义 React 组件和样式
│ ├── css/
│ │ └── custom.css # 自定义样式
│ └── pages/
│ ├── index.js # 首页
│ └── index.css # 首页样式
└── static/ # 静态资源
└── images/
└── site/ # Logo、Favicon 等
3. 站点配置
3.1 关键配置
// 站点基础信息
title: 'TGOSKits'
url: 'https://rcore-os.github.io'
baseUrl: '/tgoskits/'
organizationName: 'rcore-os'
projectName: 'tgoskits'
deploymentBranch: 'gh-pages'
// 国际化
i18n: { defaultLocale: 'zh-Hans', locales: ['zh-Hans'] }
// Mermaid 图表支持
markdown: { mermaid: true }
themes: ['@docusaurus/theme-mermaid']
3.2 Sidebar 组织
两个 sidebar 均使用自动生成模式:
// sidebars.docs.js
module.exports = {
docs: [{type: 'autogenerated', dirName: '.'}],
};
// sidebars.community.js
module.exports = {
community: [{type: 'autogenerated', dirName: '.'}],
};
目录结构和排序由各目录下的 _category_.json 文件控制:
{
"label": "组件库",
"position": 7,
"link": {
"type": "generated-index",
"title": "组件库",
"slug": "/components",
"description": "组件概述与各组件文档。"
}
}
3.3 多文档实例
除主文档(docs/docs/)外,还有一个独立的社区文档实例(docs/community/),通过 @docusaurus/plugin-content-docs 插件的额外实例实现:
plugins: [
[
'@docusaurus/plugin-content-docs',
{
id: 'community',
path: 'community',
routeBasePath: 'community',
sidebarPath: './sidebars.community.js',
},
],
],
4. 本地开发
4.1 安装依赖
cd docs
corepack enable # 启用 Corepack(管理 Yarn 版本)
yarn install # 安装依赖
4.2 启动开发服务器
yarn start
# 或指定监听地址
yarn start --host 0.0.0.0
开发服务器支持热更新(HMR),修改 Markdown 文件后浏览器会自动刷新。
4.3 构建静态站点
yarn build
构建产物位于 docs/build/。构建时会检查所有内部链接是否有效。
4.4 本地预览构建结果
yarn build
yarn serve
5. 写作规范
5.1 文档文件组织
- 每个顶层目录对应一个章节,包含
_category_.json定义标题、位置和索引页 - 文件名使用小写 + 短横线:
my-topic.md - sidebar 顺序由
_category_.json的position字段和文件内的sidebar_positionfront matter 控制