mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-11 08:07:26 +02:00
fix(content-docs): render category with no subitems as a normal link (#6495)
This commit is contained in:
parent
049b2c84c6
commit
3573b5e4a9
6 changed files with 120 additions and 5 deletions
|
@ -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') {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue