Skip to content

Commit 7e7aa39

Browse files
committed
docs: recursively flatten items
1 parent eee9dd9 commit 7e7aa39

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

docs/.vitepress/config/shared.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,26 @@ import {
1313
import tsconfigBase from "../../../tsconfig.base.json" with { type: "json" };
1414
import { MarkdownTransform, clercImports } from "../plugins/markdown-transform";
1515

16+
const flattenItems = (
17+
items: DefaultTheme.SidebarItem[],
18+
): DefaultTheme.SidebarItem[] =>
19+
items
20+
.flatMap((item) => {
21+
if (item.items && !item.link) {
22+
return flattenItems(item.items);
23+
}
24+
25+
if (item.items) {
26+
return {
27+
...item,
28+
items: flattenItems(item.items),
29+
};
30+
}
31+
32+
return item;
33+
})
34+
.toSorted((a, b) => a.text!.localeCompare(b.text!));
35+
1636
export function getTypedocSidebar(pkg: string) {
1737
const filepath = path.resolve(
1838
import.meta.dirname,
@@ -27,9 +47,7 @@ export function getTypedocSidebar(pkg: string) {
2747
readFileSync(filepath, "utf-8"),
2848
) as DefaultTheme.SidebarItem[];
2949

30-
return items
31-
.flatMap((i) => i.items!)
32-
.toSorted((a, b) => a.text!.localeCompare(b.text!));
50+
return flattenItems(items);
3351
} catch (error) {
3452
console.error(`Failed to load typedoc sidebar for ${pkg}:`, error);
3553

0 commit comments

Comments
 (0)