mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-19 17:49:19 +02:00
feat(theme-classic): new navbar item linking to a sidebar (#6139)
Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com> Co-authored-by: Joshua Chen <sidachen2003@gmail.com> Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
This commit is contained in:
parent
3cb99124de
commit
eade41a702
12 changed files with 396 additions and 13 deletions
|
@ -136,6 +136,18 @@ export type SidebarsUtils = {
|
|||
getCategoryGeneratedIndexNavigation: (
|
||||
categoryGeneratedIndexPermalink: string,
|
||||
) => SidebarNavigation;
|
||||
getFirstLink: (sidebarId: string) =>
|
||||
| {
|
||||
type: 'doc';
|
||||
id: string;
|
||||
label: string;
|
||||
}
|
||||
| {
|
||||
type: 'generated-index';
|
||||
slug: string;
|
||||
label: string;
|
||||
}
|
||||
| undefined;
|
||||
|
||||
checkSidebarsDocIds: (validDocIds: string[], sidebarFilePath: string) => void;
|
||||
};
|
||||
|
@ -264,6 +276,50 @@ Available document ids are:
|
|||
}
|
||||
}
|
||||
|
||||
function getFirstLink(sidebar: Sidebar):
|
||||
| {
|
||||
type: 'doc';
|
||||
id: string;
|
||||
label: string;
|
||||
}
|
||||
| {
|
||||
type: 'generated-index';
|
||||
slug: string;
|
||||
label: string;
|
||||
}
|
||||
| undefined {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
for (const item of sidebar) {
|
||||
if (item.type === 'doc') {
|
||||
return {
|
||||
type: 'doc',
|
||||
id: item.id,
|
||||
label: item.label ?? item.id,
|
||||
};
|
||||
} else if (item.type === 'category') {
|
||||
if (item.link?.type === 'doc') {
|
||||
return {
|
||||
type: 'doc',
|
||||
id: item.link.id,
|
||||
label: item.label,
|
||||
};
|
||||
} else if (item.link?.type === 'generated-index') {
|
||||
return {
|
||||
type: 'generated-index',
|
||||
slug: item.link.slug,
|
||||
label: item.label,
|
||||
};
|
||||
} else {
|
||||
const firstSubItem = getFirstLink(item.items);
|
||||
if (firstSubItem) {
|
||||
return firstSubItem;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
sidebars,
|
||||
getFirstDocIdOfFirstSidebar,
|
||||
|
@ -272,6 +328,7 @@ Available document ids are:
|
|||
getCategoryGeneratedIndexList,
|
||||
getCategoryGeneratedIndexNavigation,
|
||||
checkSidebarsDocIds,
|
||||
getFirstLink: (id) => getFirstLink(sidebars[id]),
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue