原始的Navbar选项有:
- 文档 (Docs) - 博客 (Blog) - ...
我希望有类似于这样的内容:
- 文档1 (Docs 1) - 文档2 (Docs 2) - 博客 (Blog) - ...
我知道我可以在一个文档中创建许多子文件夹,但由于某些原因,我想要一个两个文档结构,这可以为我提供更清晰的访问文档的方式。
如果Docusaurus目前无法提供此功能,我想问是否还有其他文档框架提供此功能?
docs
文件夹,例如 docs
、docs-api
、docs-system
。
(1) 在你的 docusaurus.config.js
文件中,配置你的默认文档:(module.exports = { // start of the module.export declaration
[…]
presets: [
[
'@docusaurus/preset-classic',
{
docs: {
routeBasePath: 'docs',
path: 'docs',
sidebarPath: require.resolve('./sidebars.js'),
lastVersion: 'current',
onlyIncludeVersions: ['current'],
},
theme: {
customCss: require.resolve('./src/css/custom.css'),
},
},
],
],
[…]
}); // end of the module-export declaration
(2)现在,神奇的事情发生了!:在同一文件中,配置您的其他文档:
(module.exports = { // start of the module.export declaration
[…]
plugins: [
[…]
[
'@docusaurus/plugin-content-docs',
{
id: 'docs-api',
path: 'docs-api',
routeBasePath: 'docs-api',
sidebarPath: require.resolve('./sidebars.js'),
},
],
[
'@docusaurus/plugin-content-docs',
{
id: 'docs-system',
path: 'docs-system',
routeBasePath: 'docs-system',
sidebarPath: require.resolve('./sidebars.js'),
},
],
],
[…]
}); // end of the module-export declaration
(3) 现在您可能希望将这些文档添加到您的导航栏中,是吗?那么就加入它们吧!
(module.exports = { // start of the module.export declaration
[…]
navbar: {
hideOnScroll: true,
title: 'your title',
logo: {
alt: '',
src: 'img/favicon.ico',
},
items: [
{
to: '/docs/Intro', // ./docs/Intro.md
label: 'Docs Title',
position: 'left',
activeBaseRegex: `/docs/`,
},
{
to: '/docs-api/Intro', // ./docs-api/Intro.md
label: 'API',
position: 'left',
activeBaseRegex: `/docs-api/`,
},
{
to: '/docs-system/Introducao', // ./docs-system/Intro.md
label: 'My System',
position: 'left',
activeBaseRegex: `/docs-system/`,
},
],
},
[…]
}); // end of the module-export declaration
重要提示
有时您会修改docusaurus.config.js
文件,但不会“工作”,因此请关闭docusaurus service
(在终端/ powershell 中只需Ctrl+C),然后重新启动它——如果我之前知道这一点,我可能会节省几个小时。
如果您没有plugin-content-docs插件,请安装它:
npm install --save @docusaurus/plugin-content-docs
路线图
我花了很大的力气才弄清楚这个问题。 我所做的是下载整个docusaurus项目,获取网站部分,删除所有我不需要的内容,这就是我得到的结果。
参考资料 (更新于2022年03月02日)
这个解决方案对我有效。在Docusaurus v2.0.0-beta.15中,使用“autogenerated”侧边栏即可。
sidebars.js
/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */
const sidebars = {
// tutorialSidebar: [{type: 'autogenerated', dirName: '.'}],
newone: [{type: 'autogenerated', dirName: 'newone'}], // foldername
newtwo: [{type: 'autogenerated', dirName: 'newtwo'}], // foldername
};
module.exports = sidebars;
docusaurus.config.js
navbar: {
title: 'My Site',
logo: {
alt: 'My Site Logo',
src: 'img/logo.svg',
},
items: [
// {
// type: 'doc',
// docId: 'intro',
// position: 'left',
// label: 'Tutorials',
// },
{
type: 'docSidebar', // docSidebar
position: 'left',
sidebarId: 'newone', // foldername
label: 'NEWONE', // navbar title
},
{
type: 'docSidebar', // docSidebar
position: 'left',
sidebarId: 'newtwo', // foldername
label: 'NEWTWO', // navbar title
},
{to: '/blog', label: 'Blog', position: 'left'},
{
href: 'https://github.com/facebook/docusaurus',
label: 'GitHub',
position: 'right',
},
],
},
docs/
newone/
intro.md
newtwo/
intro.md
activeBasePath
属性,则具有相同路径(在本例中为docs
)的链接将具有活动属性。
sidebar.js
module.exports = {
someSidebar: {
Docusaurus: ['doc1', 'doc2'],
Features: ['doc3']
},
someOtherSidebar: {
Test: ['mdx']
}
};
docusaurus.config.js
导航栏链接如下 -links: [
{
to: 'docs/doc1',
// activeBasePath: 'docs', // [Edit 3]
label: 'Docs',
position: 'left'
},
{
to: 'docs/mdx',
label: 'API',
position: 'left'
},
]
docs文件夹的文件夹结构如下所示 -
docs
├── docs1.md
├── mdx.md
sidebars.js
配置都可以包含多个键, 每个键都有自己的侧边栏。sidebars.js
我们可以在 /docs
路径下创建多个分区。但他所要求的是创建两个独立的文档文件夹 API 和 docs,它们具有与 docs 相同的功能。这在 docusaurus 导航栏的 v1 版本中已经存在。 - Germa Vinsmoke.mdx
文件移动到其中。但是它没有起作用。 - Germa Vinsmokedocs-xxxxxxxxx
"!不要创建其他名称,比如"education",否则页面会崩溃!将Docusaurus设置为多实例需要跨越许多文件进行更改。为了使其更容易设置,我创建了一个基本安装程序,其中包含所有必要的更改以进行多实例,并将其发布为GitHub模板。
在此处分叉:
mg0716/docusaurus-multi
该存储库中的许多更改都是由@d-kastier的原始comment导致的。
非常乐意接受反馈和拉取请求,所以请随时尝试!
你需要在docusaurus配置中使用文档类型。我认为“to”类型是针对页面而不是文档的。
为了使侧边栏正确,你还需要设置配置中的activeSidebarClassName值,以便它知道你想要为这个文档使用哪个侧边栏(在sidebars.js中导出的那些侧边栏之一)。
activeSidebarClassName: 'navbar__link--active',
https://docusaurus.io/docs/api/themes/configuration#navbar-doc-link