mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-15 18:17:35 +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
|
@ -5,11 +5,16 @@
|
|||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {mapValues} from 'lodash';
|
||||
import {normalizeUrl} from '@docusaurus/utils';
|
||||
import type {Sidebars} from './sidebars/types';
|
||||
import {createSidebarsUtils} from './sidebars/utils';
|
||||
import type {
|
||||
DocMetadata,
|
||||
GlobalDoc,
|
||||
LoadedVersion,
|
||||
GlobalVersion,
|
||||
GlobalSidebar,
|
||||
} from './types';
|
||||
|
||||
export function toGlobalDataDoc(doc: DocMetadata): GlobalDoc {
|
||||
|
@ -20,6 +25,31 @@ export function toGlobalDataDoc(doc: DocMetadata): GlobalDoc {
|
|||
};
|
||||
}
|
||||
|
||||
export function toGlobalSidebars(
|
||||
sidebars: Sidebars,
|
||||
version: LoadedVersion,
|
||||
): Record<string, GlobalSidebar> {
|
||||
const {getFirstLink} = createSidebarsUtils(sidebars);
|
||||
return mapValues(sidebars, (sidebar, sidebarId) => {
|
||||
const firstLink = getFirstLink(sidebarId);
|
||||
if (!firstLink) {
|
||||
return {};
|
||||
}
|
||||
return {
|
||||
link: {
|
||||
path:
|
||||
firstLink.type === 'generated-index'
|
||||
? normalizeUrl([version.versionPath, firstLink.slug])
|
||||
: version.docs.find(
|
||||
(doc) =>
|
||||
doc.id === firstLink.id || doc.unversionedId === firstLink.id,
|
||||
)!.permalink,
|
||||
label: firstLink.label,
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export function toGlobalDataVersion(version: LoadedVersion): GlobalVersion {
|
||||
return {
|
||||
name: version.versionName,
|
||||
|
@ -28,5 +58,6 @@ export function toGlobalDataVersion(version: LoadedVersion): GlobalVersion {
|
|||
path: version.versionPath,
|
||||
mainDocId: version.mainDocId,
|
||||
docs: version.docs.map(toGlobalDataDoc),
|
||||
sidebars: toGlobalSidebars(version.sidebars, version),
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue