Skip to content

Commit

Permalink
feat: support subpage overview
Browse files Browse the repository at this point in the history
  • Loading branch information
Timeless0911 committed Apr 2, 2024
1 parent 04109e0 commit 6d89a48
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-swans-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rspress/theme-default": minor
---

feat: support subpage overview
28 changes: 26 additions & 2 deletions packages/theme-default/src/components/Overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,35 @@ export function Overview(props: {
}
return '';
};
const findItemByRoutePath = (items, routePath, originalItems) => {
for (const item of items) {
if (item.link === routePath) {
return [item];
}
if (item.items) {
const foundItem = findItemByRoutePath(
item.items,
routePath,
originalItems,
);
if (foundItem) {
return foundItem;
}
}
}
return originalItems;
};
const { pages } = siteData;
const overviewModules = pages.filter(page => subFilter(page.routePath));
const { items: overviewSidebarGroups } = useSidebarData() as {
let { items: overviewSidebarGroups } = useSidebarData() as {
items: (NormalizedSidebarGroup | SidebarItem)[];
};
overviewSidebarGroups = findItemByRoutePath(
overviewSidebarGroups,
routePath,
overviewSidebarGroups,
);

function normalizeSidebarItem(
item: SidebarItem | SidebarDivider | NormalizedSidebarGroup,
sidebarGroup?: NormalizedSidebarGroup,
Expand Down Expand Up @@ -121,7 +145,7 @@ export function Overview(props: {
]
: []),
];
}, [overviewSidebarGroups]);
}, [overviewSidebarGroups, routePath]);

return (
<div className="overview-index mx-auto px-8">
Expand Down

0 comments on commit 6d89a48

Please sign in to comment.