feat(v2): allow infinitely nested sidebar (#1812)

* feat(v2): allow infinitely nested sidebar

* Update markdown-features.mdx

* Update sidebar.md

* Update sidebar.md
This commit is contained in:
Endi 2019-10-08 01:52:43 +07:00 committed by Yangshun Tay
parent 1591128cdd
commit 95f0552bad
7 changed files with 282 additions and 41 deletions

View file

@ -0,0 +1,44 @@
/*
* Copyright (c) 2017-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
module.exports = {
docs: [
{
type: 'category',
label: 'level 1',
items: [
'a',
{
type: 'category',
label: 'level 2',
items: [
{
type: 'category',
label: 'level 3',
items: [
'c',
{
type: 'category',
label: 'level 4',
items: [
'd',
{
type: 'category',
label: 'deeper more more',
items: ['e'],
},
],
},
],
},
'f',
],
},
],
},
],
};

View file

@ -1,5 +1,62 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`loadSidebars sidebars with deep level of category 1`] = `
Object {
"docs": Array [
Object {
"items": Array [
Object {
"id": "a",
"type": "doc",
},
Object {
"items": Array [
Object {
"items": Array [
Object {
"id": "c",
"type": "doc",
},
Object {
"items": Array [
Object {
"id": "d",
"type": "doc",
},
Object {
"items": Array [
Object {
"id": "e",
"type": "doc",
},
],
"label": "deeper more more",
"type": "category",
},
],
"label": "level 4",
"type": "category",
},
],
"label": "level 3",
"type": "category",
},
Object {
"id": "f",
"type": "doc",
},
],
"label": "level 2",
"type": "category",
},
],
"label": "level 1",
"type": "category",
},
],
}
`;
exports[`loadSidebars sidebars with known sidebar item type 1`] = `
Object {
"docs": Array [

View file

@ -22,6 +22,17 @@ describe('loadSidebars', () => {
expect(result).toMatchSnapshot();
});
test('sidebars with deep level of category', async () => {
const sidebarPath = path.join(
__dirname,
'__fixtures__',
'website',
'sidebars-category.js',
);
const result = loadSidebars(sidebarPath);
expect(result).toMatchSnapshot();
});
test('sidebars with unknown sidebar item type', async () => {
const sidebarPath = path.join(
__dirname,

View file

@ -40,14 +40,6 @@ function normalizeCategory(
category: SidebarItemCategoryRaw,
level = 0,
): SidebarItemCategory {
if (level === 2) {
throw new Error(
`Can not process ${
category.label
} category. Categories can be nested only one level deep.`,
);
}
assertItem(category, ['items', 'label']);
if (!Array.isArray(category.items)) {