fix(v2): sidebar autogen from subfolder should read category metadata correctly ()

* fix sidebar autogen bug

* fix sidebar autogen bug
This commit is contained in:
Sébastien Lorber 2021-04-20 18:16:51 +02:00 committed by GitHub
parent 03536a0682
commit d0d29f43cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 162 additions and 0 deletions
packages/docusaurus-plugin-content-docs/src/__tests__

View file

@ -219,6 +219,20 @@ describe('DefaultSidebarItemsGenerator', () => {
});
test('generates subfolder sidebar', async () => {
// Ensure that category metadata file is correctly read
// fix edge case found in https://github.com/facebook/docusaurus/issues/4638
mockCategoryMetadataFiles({
'subfolder/subsubfolder/subsubsubfolder2/_category_.yml': {
position: 2,
label: 'subsubsubfolder2 (_category_.yml label)',
},
'subfolder/subsubfolder/subsubsubfolder3/_category_.json': {
position: 1,
label: 'subsubsubfolder3 (_category_.json label)',
collapsed: false,
},
});
const sidebarSlice = await DefaultSidebarItemsGenerator({
item: {
type: 'autogenerated',
@ -257,12 +271,61 @@ describe('DefaultSidebarItemsGenerator', () => {
sidebarPosition: undefined,
frontMatter: {},
},
{
id: 'doc5',
source: 'doc5.md',
sourceDirName: 'subfolder/subsubfolder/subsubsubfolder',
sidebarPosition: undefined,
frontMatter: {},
},
{
id: 'doc6',
source: 'doc6.md',
sourceDirName: 'subfolder/subsubfolder/subsubsubfolder2',
sidebarPosition: undefined,
frontMatter: {},
},
{
id: 'doc7',
source: 'doc7.md',
sourceDirName: 'subfolder/subsubfolder/subsubsubfolder3',
sidebarPosition: 2,
frontMatter: {},
},
{
id: 'doc8',
source: 'doc8.md',
sourceDirName: 'subfolder/subsubfolder/subsubsubfolder3',
sidebarPosition: 1,
frontMatter: {},
},
],
});
expect(sidebarSlice).toEqual([
{
type: 'category',
label: 'subsubsubfolder3 (_category_.json label)',
collapsed: false,
items: [
{type: 'doc', id: 'doc8'},
{type: 'doc', id: 'doc7'},
],
},
{
type: 'category',
label: 'subsubsubfolder2 (_category_.yml label)',
collapsed: true,
items: [{type: 'doc', id: 'doc6'}],
},
{type: 'doc', id: 'doc1'},
{type: 'doc', id: 'doc4'},
{
type: 'category',
label: 'subsubsubfolder',
collapsed: true,
items: [{type: 'doc', id: 'doc5'}],
},
] as Sidebar);
});
});