Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/fuzzy-corners-write.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
36 changes: 35 additions & 1 deletion docs/components/geistdocs/docs-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,43 @@ const addSidebarBadges = (nodes: DocsTreeNode[]): DocsTreeNode[] =>
return node;
});

// A folder with no index page can't be clicked, only expanded/collapsed —
// fall back to its first descendant page so every sidebar category navigates.
type PageNode = Extract<DocsTreeNode, { type: 'page' }>;

const findFirstPage = (nodes: DocsTreeNode[]): PageNode | undefined => {
for (const node of nodes) {
if (node.type === 'page') {
return node;
}
if (node.type === 'folder') {
const found = node.index ?? findFirstPage(node.children);
if (found) {
return found;
}
}
}
return undefined;
};

const withFallbackFolderIndex = (nodes: DocsTreeNode[]): DocsTreeNode[] =>
nodes.map((node) => {
if (node.type !== 'folder') {
return node;
}

const children = withFallbackFolderIndex(node.children);

return {
...node,
children,
index: node.index ?? findFirstPage(children),
};
});

const addSidebarBadgesToTree = (tree: DocsTree): DocsTree => ({
...tree,
children: addSidebarBadges(tree.children),
children: addSidebarBadges(withFallbackFolderIndex(tree.children)),
});

interface DocsLayoutProps {
Expand Down
Loading