mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-16 10:37:20 +02:00
fix: highlight appropriate navItem based on active sidebar item (#6310)
* fix: highlight appropriate navItem based on active sidebar item * fix: try using location.pathname * fix: remote console.log * fix: include category generated indices in globalData * Add test * fix snap Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
This commit is contained in:
parent
6e75d035bb
commit
3e5944ef1f
5 changed files with 73 additions and 9 deletions
|
@ -9,7 +9,11 @@ import {mapValues} from 'lodash';
|
|||
import {normalizeUrl} from '@docusaurus/utils';
|
||||
import type {Sidebars} from './sidebars/types';
|
||||
import {createSidebarsUtils} from './sidebars/utils';
|
||||
import type {DocMetadata, LoadedVersion} from './types';
|
||||
import type {
|
||||
CategoryGeneratedIndexMetadata,
|
||||
DocMetadata,
|
||||
LoadedVersion,
|
||||
} from './types';
|
||||
import type {
|
||||
GlobalVersion,
|
||||
GlobalSidebar,
|
||||
|
@ -24,6 +28,16 @@ export function toGlobalDataDoc(doc: DocMetadata): GlobalDoc {
|
|||
};
|
||||
}
|
||||
|
||||
export function toGlobalDataGeneratedIndex(
|
||||
doc: CategoryGeneratedIndexMetadata,
|
||||
): GlobalDoc {
|
||||
return {
|
||||
id: doc.slug,
|
||||
path: doc.permalink,
|
||||
sidebar: doc.sidebar,
|
||||
};
|
||||
}
|
||||
|
||||
export function toGlobalSidebars(
|
||||
sidebars: Sidebars,
|
||||
version: LoadedVersion,
|
||||
|
@ -56,7 +70,9 @@ export function toGlobalDataVersion(version: LoadedVersion): GlobalVersion {
|
|||
isLast: version.isLast,
|
||||
path: version.versionPath,
|
||||
mainDocId: version.mainDocId,
|
||||
docs: version.docs.map(toGlobalDataDoc),
|
||||
docs: version.docs
|
||||
.map(toGlobalDataDoc)
|
||||
.concat(version.categoryGeneratedIndices.map(toGlobalDataGeneratedIndex)),
|
||||
sidebars: toGlobalSidebars(version.sidebars, version),
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue