Skip to main content

管理文档版本

Docusaurus 可以管理您的文档的多个版本。

创建文档版本

发布您项目的 1.0 版本:

npm run docusaurus docs:version 1.0

docs 文件夹将被复制到 versioned_docs/version-1.0,并创建 versions.json

您的文档现在有两个版本:

  • 1.0http://localhost:3000/docs/ 用于 1.0 版本的文档
  • currenthttp://localhost:3000/docs/next/ 用于 即将发布的文档

添加版本下拉菜单

为了在不同版本之间无缝导航,添加一个版本下拉菜单。

修改 docusaurus.config.js 文件:

docusaurus.config.js
export default {
themeConfig: {
navbar: {
items: [
{
type: 'docsVersionDropdown',
},
],
},
},
};

文档版本下拉菜单出现在您的导航栏中:

文档版本下拉菜单

更新现有版本

可以在各自的文件夹中编辑版本化的文档:

  • versioned_docs/version-1.0/hello.md 更新 http://localhost:3000/docs/hello
  • docs/hello.md 更新 http://localhost:3000/docs/next/hello