mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 15:47:23 +02:00
This reverts commit 1863a3c805
.
This commit is contained in:
parent
7d792840ba
commit
510bec6532
11 changed files with 3 additions and 176 deletions
|
@ -9,30 +9,25 @@ module.exports = {
|
||||||
docs: [
|
docs: [
|
||||||
{
|
{
|
||||||
type: 'category',
|
type: 'category',
|
||||||
collapsed: true,
|
|
||||||
label: 'level 1',
|
label: 'level 1',
|
||||||
items: [
|
items: [
|
||||||
'a',
|
'a',
|
||||||
{
|
{
|
||||||
type: 'category',
|
type: 'category',
|
||||||
collapsed: true,
|
|
||||||
label: 'level 2',
|
label: 'level 2',
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
type: 'category',
|
type: 'category',
|
||||||
collapsed: true,
|
|
||||||
label: 'level 3',
|
label: 'level 3',
|
||||||
items: [
|
items: [
|
||||||
'c',
|
'c',
|
||||||
{
|
{
|
||||||
type: 'category',
|
type: 'category',
|
||||||
collapsed: true,
|
|
||||||
label: 'level 4',
|
label: 'level 4',
|
||||||
items: [
|
items: [
|
||||||
'd',
|
'd',
|
||||||
{
|
{
|
||||||
type: 'category',
|
type: 'category',
|
||||||
collapsed: true,
|
|
||||||
label: 'deeper more more',
|
label: 'deeper more more',
|
||||||
items: ['e'],
|
items: ['e'],
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
{
|
|
||||||
"docs": [
|
|
||||||
{
|
|
||||||
"type": "category",
|
|
||||||
"label": "Introduction",
|
|
||||||
"items": [
|
|
||||||
"doc1"
|
|
||||||
],
|
|
||||||
"collapsed": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "category",
|
|
||||||
"label": "Powering MDX",
|
|
||||||
"items": [
|
|
||||||
"doc2"
|
|
||||||
],
|
|
||||||
"collapsed": false
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
{
|
|
||||||
"docs": {
|
|
||||||
"Test": [
|
|
||||||
{
|
|
||||||
"type": "category",
|
|
||||||
"label": "Introduction",
|
|
||||||
"items": ["doc1"],
|
|
||||||
"collapsed": false
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"Reference": [
|
|
||||||
{
|
|
||||||
"type": "category",
|
|
||||||
"label": "Powering MDX",
|
|
||||||
"items": ["doc2"],
|
|
||||||
"collapsed": false
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ exports[`simple website content 1`] = `
|
||||||
Object {
|
Object {
|
||||||
"docs": Array [
|
"docs": Array [
|
||||||
Object {
|
Object {
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"items": Array [
|
"items": Array [
|
||||||
|
@ -37,7 +36,6 @@ Object {
|
||||||
"type": "category",
|
"type": "category",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"href": "/docs/hello",
|
"href": "/docs/hello",
|
||||||
|
@ -202,7 +200,6 @@ exports[`versioned website content: all sidebars 1`] = `
|
||||||
Object {
|
Object {
|
||||||
"docs": Array [
|
"docs": Array [
|
||||||
Object {
|
Object {
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"href": "/docs/next/foo/bar",
|
"href": "/docs/next/foo/bar",
|
||||||
|
@ -214,7 +211,6 @@ Object {
|
||||||
"type": "category",
|
"type": "category",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"href": "/docs/next/hello",
|
"href": "/docs/next/hello",
|
||||||
|
@ -228,7 +224,6 @@ Object {
|
||||||
],
|
],
|
||||||
"version-1.0.0/docs": Array [
|
"version-1.0.0/docs": Array [
|
||||||
Object {
|
Object {
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"href": "/docs/1.0.0/foo/bar",
|
"href": "/docs/1.0.0/foo/bar",
|
||||||
|
@ -245,7 +240,6 @@ Object {
|
||||||
"type": "category",
|
"type": "category",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"href": "/docs/1.0.0/hello",
|
"href": "/docs/1.0.0/hello",
|
||||||
|
@ -259,7 +253,6 @@ Object {
|
||||||
],
|
],
|
||||||
"version-1.0.1/docs": Array [
|
"version-1.0.1/docs": Array [
|
||||||
Object {
|
Object {
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"href": "/docs/foo/bar",
|
"href": "/docs/foo/bar",
|
||||||
|
@ -271,7 +264,6 @@ Object {
|
||||||
"type": "category",
|
"type": "category",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"href": "/docs/hello",
|
"href": "/docs/hello",
|
||||||
|
@ -291,7 +283,6 @@ Object {
|
||||||
"docsSidebars": Object {
|
"docsSidebars": Object {
|
||||||
"version-1.0.0/docs": Array [
|
"version-1.0.0/docs": Array [
|
||||||
Object {
|
Object {
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"href": "/docs/1.0.0/foo/bar",
|
"href": "/docs/1.0.0/foo/bar",
|
||||||
|
@ -308,7 +299,6 @@ Object {
|
||||||
"type": "category",
|
"type": "category",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"href": "/docs/1.0.0/hello",
|
"href": "/docs/1.0.0/hello",
|
||||||
|
@ -335,7 +325,6 @@ Object {
|
||||||
"docsSidebars": Object {
|
"docsSidebars": Object {
|
||||||
"version-1.0.1/docs": Array [
|
"version-1.0.1/docs": Array [
|
||||||
Object {
|
Object {
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"href": "/docs/foo/bar",
|
"href": "/docs/foo/bar",
|
||||||
|
@ -347,7 +336,6 @@ Object {
|
||||||
"type": "category",
|
"type": "category",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"href": "/docs/hello",
|
"href": "/docs/hello",
|
||||||
|
@ -373,7 +361,6 @@ Object {
|
||||||
"docsSidebars": Object {
|
"docsSidebars": Object {
|
||||||
"docs": Array [
|
"docs": Array [
|
||||||
Object {
|
Object {
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"href": "/docs/next/foo/bar",
|
"href": "/docs/next/foo/bar",
|
||||||
|
@ -385,7 +372,6 @@ Object {
|
||||||
"type": "category",
|
"type": "category",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"href": "/docs/next/hello",
|
"href": "/docs/next/hello",
|
||||||
|
|
|
@ -4,7 +4,6 @@ exports[`loadSidebars sidebars link 1`] = `
|
||||||
Object {
|
Object {
|
||||||
"docs": Array [
|
"docs": Array [
|
||||||
Object {
|
Object {
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"href": "https://github.com",
|
"href": "https://github.com",
|
||||||
|
@ -19,107 +18,30 @@ Object {
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`loadSidebars sidebars with category.collapsed property 1`] = `
|
|
||||||
Object {
|
|
||||||
"docs": Array [
|
|
||||||
Object {
|
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
|
||||||
Object {
|
|
||||||
"collapsed": false,
|
|
||||||
"items": Array [
|
|
||||||
Object {
|
|
||||||
"id": "doc1",
|
|
||||||
"type": "doc",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
"label": "Introduction",
|
|
||||||
"type": "category",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
"label": "Test",
|
|
||||||
"type": "category",
|
|
||||||
},
|
|
||||||
Object {
|
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
|
||||||
Object {
|
|
||||||
"collapsed": false,
|
|
||||||
"items": Array [
|
|
||||||
Object {
|
|
||||||
"id": "doc2",
|
|
||||||
"type": "doc",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
"label": "Powering MDX",
|
|
||||||
"type": "category",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
"label": "Reference",
|
|
||||||
"type": "category",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`loadSidebars sidebars with category.collapsed property at first level 1`] = `
|
|
||||||
Object {
|
|
||||||
"docs": Array [
|
|
||||||
Object {
|
|
||||||
"collapsed": false,
|
|
||||||
"items": Array [
|
|
||||||
Object {
|
|
||||||
"id": "doc1",
|
|
||||||
"type": "doc",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
"label": "Introduction",
|
|
||||||
"type": "category",
|
|
||||||
},
|
|
||||||
Object {
|
|
||||||
"collapsed": false,
|
|
||||||
"items": Array [
|
|
||||||
Object {
|
|
||||||
"id": "doc2",
|
|
||||||
"type": "doc",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
"label": "Powering MDX",
|
|
||||||
"type": "category",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}
|
|
||||||
`;
|
|
||||||
|
|
||||||
exports[`loadSidebars sidebars with deep level of category 1`] = `
|
exports[`loadSidebars sidebars with deep level of category 1`] = `
|
||||||
Object {
|
Object {
|
||||||
"docs": Array [
|
"docs": Array [
|
||||||
Object {
|
Object {
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"id": "a",
|
"id": "a",
|
||||||
"type": "doc",
|
"type": "doc",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"id": "c",
|
"id": "c",
|
||||||
"type": "doc",
|
"type": "doc",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"id": "d",
|
"id": "d",
|
||||||
"type": "doc",
|
"type": "doc",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"id": "e",
|
"id": "e",
|
||||||
|
@ -178,7 +100,6 @@ exports[`loadSidebars sidebars with known sidebar item type 1`] = `
|
||||||
Object {
|
Object {
|
||||||
"docs": Array [
|
"docs": Array [
|
||||||
Object {
|
Object {
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"id": "foo/bar",
|
"id": "foo/bar",
|
||||||
|
@ -202,7 +123,6 @@ Object {
|
||||||
"type": "category",
|
"type": "category",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"id": "hello",
|
"id": "hello",
|
||||||
|
|
|
@ -4,7 +4,6 @@ exports[`docsVersion first time versioning 1`] = `
|
||||||
Object {
|
Object {
|
||||||
"version-1.0.0/docs": Array [
|
"version-1.0.0/docs": Array [
|
||||||
Object {
|
Object {
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"items": Array [
|
"items": Array [
|
||||||
|
@ -34,7 +33,6 @@ Object {
|
||||||
"type": "category",
|
"type": "category",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"id": "version-1.0.0/hello",
|
"id": "version-1.0.0/hello",
|
||||||
|
@ -52,7 +50,6 @@ exports[`docsVersion not the first time versioning 1`] = `
|
||||||
Object {
|
Object {
|
||||||
"version-2.0.0/docs": Array [
|
"version-2.0.0/docs": Array [
|
||||||
Object {
|
Object {
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"id": "version-2.0.0/foo/bar",
|
"id": "version-2.0.0/foo/bar",
|
||||||
|
@ -63,7 +60,6 @@ Object {
|
||||||
"type": "category",
|
"type": "category",
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"collapsed": true,
|
|
||||||
"items": Array [
|
"items": Array [
|
||||||
Object {
|
Object {
|
||||||
"id": "version-2.0.0/hello",
|
"id": "version-2.0.0/hello",
|
||||||
|
|
|
@ -126,19 +126,4 @@ describe('loadSidebars', () => {
|
||||||
const result = loadSidebars(null);
|
const result = loadSidebars(null);
|
||||||
expect(result).toEqual({});
|
expect(result).toEqual({});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('sidebars with category.collapsed property', async () => {
|
|
||||||
const sidebarPath = path.join(fixtureDir, 'sidebars-collapsed.json');
|
|
||||||
const result = loadSidebars([sidebarPath]);
|
|
||||||
expect(result).toMatchSnapshot();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('sidebars with category.collapsed property at first level', async () => {
|
|
||||||
const sidebarPath = path.join(
|
|
||||||
fixtureDir,
|
|
||||||
'sidebars-collapsed-first-level.json',
|
|
||||||
);
|
|
||||||
const result = loadSidebars([sidebarPath]);
|
|
||||||
expect(result).toMatchSnapshot();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -33,7 +33,6 @@ function normalizeCategoryShorthand(
|
||||||
): SidebarItemCategoryRaw[] {
|
): SidebarItemCategoryRaw[] {
|
||||||
return Object.entries(sidebar).map(([label, items]) => ({
|
return Object.entries(sidebar).map(([label, items]) => ({
|
||||||
type: 'category',
|
type: 'category',
|
||||||
collapsed: true,
|
|
||||||
label,
|
label,
|
||||||
items,
|
items,
|
||||||
}));
|
}));
|
||||||
|
@ -57,7 +56,7 @@ function assertItem(item: Object, keys: string[]): void {
|
||||||
}
|
}
|
||||||
|
|
||||||
function assertIsCategory(item: any): asserts item is SidebarItemCategoryRaw {
|
function assertIsCategory(item: any): asserts item is SidebarItemCategoryRaw {
|
||||||
assertItem(item, ['items', 'label', 'collapsed']);
|
assertItem(item, ['items', 'label']);
|
||||||
if (typeof item.label !== 'string') {
|
if (typeof item.label !== 'string') {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Error loading ${JSON.stringify(item)}. "label" must be a string.`,
|
`Error loading ${JSON.stringify(item)}. "label" must be a string.`,
|
||||||
|
@ -68,12 +67,6 @@ function assertIsCategory(item: any): asserts item is SidebarItemCategoryRaw {
|
||||||
`Error loading ${JSON.stringify(item)}. "items" must be an array.`,
|
`Error loading ${JSON.stringify(item)}. "items" must be an array.`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// "collapsed" is an optional property
|
|
||||||
if (item.hasOwnProperty('collapsed') && typeof item.collapsed !== 'boolean') {
|
|
||||||
throw new Error(
|
|
||||||
`Error loading ${JSON.stringify(item)}. "collapsed" must be a boolean.`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function assertIsDoc(item: any): asserts item is SidebarItemDoc {
|
function assertIsDoc(item: any): asserts item is SidebarItemDoc {
|
||||||
|
|
|
@ -40,14 +40,12 @@ export interface SidebarItemCategory {
|
||||||
type: 'category';
|
type: 'category';
|
||||||
label: string;
|
label: string;
|
||||||
items: SidebarItem[];
|
items: SidebarItem[];
|
||||||
collapsed?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SidebarItemCategoryRaw {
|
export interface SidebarItemCategoryRaw {
|
||||||
type: 'category';
|
type: 'category';
|
||||||
label: string;
|
label: string;
|
||||||
items: SidebarItemRaw[];
|
items: SidebarItemRaw[];
|
||||||
collapsed?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SidebarItem =
|
export type SidebarItem =
|
||||||
|
@ -83,7 +81,6 @@ export interface DocsSidebarItemCategory {
|
||||||
type: 'category';
|
type: 'category';
|
||||||
label: string;
|
label: string;
|
||||||
items: DocsSidebarItem[];
|
items: DocsSidebarItem[];
|
||||||
collapsed?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DocsSidebarItem = SidebarItemLink | DocsSidebarItemCategory;
|
export type DocsSidebarItem = SidebarItemLink | DocsSidebarItemCategory;
|
||||||
|
|
|
@ -105,11 +105,8 @@ function mutateSidebarCollapsingState(item, path) {
|
||||||
items
|
items
|
||||||
.map((childItem) => mutateSidebarCollapsingState(childItem, path))
|
.map((childItem) => mutateSidebarCollapsingState(childItem, path))
|
||||||
.filter((val) => val).length > 0;
|
.filter((val) => val).length > 0;
|
||||||
// only modify item.collapsed if there are child items active and the category collapsed is set to true
|
// eslint-disable-next-line no-param-reassign
|
||||||
if (anyChildItemsActive && item.collapsed) {
|
item.collapsed = !anyChildItemsActive;
|
||||||
// eslint-disable-next-line no-param-reassign
|
|
||||||
item.collapsed = !anyChildItemsActive;
|
|
||||||
}
|
|
||||||
return anyChildItemsActive;
|
return anyChildItemsActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -207,7 +207,6 @@ type SidebarItemCategory = {
|
||||||
type: 'category';
|
type: 'category';
|
||||||
label: string; // Sidebar label text.
|
label: string; // Sidebar label text.
|
||||||
items: SidebarItem[]; // Array of sidebar items.
|
items: SidebarItem[]; // Array of sidebar items.
|
||||||
collapsed: boolean; // Set the category to be collapsed or open by default
|
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue