add references sidebar

This commit is contained in:
Shahed Nasser
2025-03-10 15:11:42 +02:00
parent 11db301f9b
commit affd5e83d4
9 changed files with 6878 additions and 6793 deletions

View File

@@ -264,27 +264,41 @@ export const useChildDocs = ({
}, [isBrowser, searchQuery, storageKey, enableSearch])
const getTopLevelElms = (items?: Sidebar.InteractiveSidebarItem[]) => {
const itemsToShow: {
[k: string]: Sidebar.InteractiveSidebarItem
} = {}
items?.forEach((childItem) => {
const href = isSidebarItemLink(childItem)
? childItem.path
: childItem.type === "sidebar"
? getSidebarFirstLinkChild(childItem)?.path
: (
childItem.children?.find((item) =>
isSidebarItemLink(item)
) as Sidebar.SidebarItemLink
)?.path
if (!href) {
return
}
itemsToShow[href] = childItem
})
const itemsToShowEntries = Object.entries(itemsToShow)
if (!itemsToShowEntries.length) {
return <></>
}
return (
<CardList
items={
items?.map((childItem) => {
const href = isSidebarItemLink(childItem)
? childItem.path
: childItem.children?.length
? (
childItem.children.find((item) =>
isSidebarItemLink(item)
) as Sidebar.SidebarItemLink
)?.path
: "#"
return {
title: childItem.title,
href,
rightIcon:
childItem.type === "ref" ? ChevronDoubleRight : undefined,
}
}) || []
}
items={itemsToShowEntries.map(([href, childItem]) => {
return {
title: childItem.title,
href,
rightIcon:
childItem.type === "ref" ? ChevronDoubleRight : undefined,
text: childItem.description,
}
})}
itemsPerRow={itemsPerRow}
defaultItemsPerRow={defaultItemsPerRow}
/>