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:
Minh Pham 2022-01-06 05:52:25 -05:00 committed by GitHub
parent 3cb99124de
commit eade41a702
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 396 additions and 13 deletions

View file

@ -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]),
};
}