fix(content-docs): render category with no subitems as a normal link (#6495)

This commit is contained in:
Joshua Chen 2022-02-02 21:45:00 +08:00 committed by GitHub
parent 049b2c84c6
commit 3573b5e4a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 120 additions and 5 deletions

View file

@ -117,6 +117,34 @@ async function processSidebar(
item: NormalizedSidebarItem,
): Promise<SidebarItem[]> {
if (item.type === 'category') {
// If the current category doesn't have subitems, we render a normal doc link instead.
if (item.items.length === 0) {
if (!item.link) {
throw new Error(
`Sidebar category ${item.label} has neither any subitem nor a link. This makes this item not able to link to anything.`,
);
}
switch (item.link.type) {
case 'doc':
return [
{
type: 'doc',
label: item.label,
id: item.link.id,
},
];
case 'generated-index':
return [
{
type: 'link',
label: item.label,
href: item.link.permalink,
},
];
default:
throw new Error('Unexpected sidebar category link type');
}
}
return [await processCategoryItem(item)];
}
if (item.type === 'autogenerated') {