fix(theme): Fix <DocCardList> usage on docs at root of a sidebar (#10847)

Fix `<DocCardList>` usage on docs at root of a sidebar
This commit is contained in:
Sébastien Lorber 2025-01-16 21:53:41 +01:00 committed by GitHub
parent e59355be76
commit 67207bc5e5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 155 additions and 3 deletions

View file

@ -132,6 +132,25 @@ export function useCurrentSidebarCategory(): PropSidebarItemCategory {
return deepestCategory;
}
/**
* Gets the category associated with the current location. Should only be used
* on category index pages.
*/
export function useCurrentSidebarSiblings(): PropSidebarItem[] {
const {pathname} = useLocation();
const sidebar = useDocsSidebar();
if (!sidebar) {
throw new Error('Unexpected: cant find current sidebar in context');
}
const categoryBreadcrumbs = getSidebarBreadcrumbs({
sidebarItems: sidebar.items,
pathname,
onlyCategories: true,
});
const deepestCategory = categoryBreadcrumbs.slice(-1)[0];
return deepestCategory?.items ?? sidebar.items;
}
const isActive = (testedPath: string | undefined, activePath: string) =>
typeof testedPath !== 'undefined' && isSamePath(testedPath, activePath);
const containsActiveSidebarItem = (