2

是否可以根据您所在网站的哪个部分显示不同的侧边栏?因此,如果我有两个部分(BooksCountries),那么我可以显示相应的侧边栏菜单对象:

module.exports = {
    books: {
        "Children's Book": [
            "books/childrens-books/winnie-the-pooh",
            "books/childrens-books/harry-potter",
        ],
        "Non-Fiction": [
            "books/non-fiction/hitchikers-guide",
            "books/non-fiction/a-history-of-england",
        ]
    },
    countries: {
        "Europe": [
            "countries/europe/england",
            "countries/europe/france",
            "countries/europe/spain",
        ],
        "Asia": [
            "countries/asia/china",
            "countries/asia/india",
            "countries/asia/laos",
        ],
    },
}

文档确实提到可以做这样的事情,但没有任何例子可以做:

通过向导出的对象添加更多顶级键,您可以为不同的 Markdown 文件创建多个侧边栏。

我可以找到引用的侧边栏的唯一其他地方是 in docusaurus.config.js,但我不确定此部分的用途:

presets: [
    [
        '@docusaurus/preset-classic',
            {
                docs: {
                    sidebarPath: require.resolve('./sidebars.js'),
                },
...

任何指针表示赞赏!

4

1 回答 1

1

所以问题是我的内容结构与我在sidebar.js. 这是我现在的内容结构:

docs
├── README.md
├── books
│   ├── childrens-books
│   │   ├── harry-potter.md
│   │   └── winnie-the-pooh.md
│   └── non-fiction
│       ├── a-history-of-england.md
│       └── hitchikers-guide.md
└── countries
    ├── asia
    │   ├── china.md
    │   ├── india.md
    │   └── laos.md
    └── europe
        ├── england.md
        ├── france.md
        └── spain.md
├── docs
├── docusaurus.config.js
├── sidebars.js
└── src

我认为问题在于 Docusaurus 找不到我引用的文章,所以它只是没有解析。

使用此设置 URL,likelocalhost:3000/docs/books/childrens-books/harry-potter可以正常工作,但localhost:3000/docs/books/childrens-books/会返回空白页面,因为该 URL 没有相应的文章。

于 2019-10-01T19:29:07.823 回答