Skip to content

Commit

Permalink
fix: withbase routepath
Browse files Browse the repository at this point in the history
  • Loading branch information
Timeless0911 committed Apr 7, 2024
1 parent 21d9c70 commit f719ce6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/document/docs/en/fragments/internal-components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ export interface OverviewProps {
content?: React.ReactNode;
// data
groups?: Group[];
// default title
defaultGroupTitle?: string;
// minimum title displayed in the overview page of the file
overviewDepth?: 'h1' | 'h2';
}
```

Expand Down
2 changes: 2 additions & 0 deletions packages/document/docs/zh/fragments/internal-components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ export interface OverviewProps {
groups?: Group[];
// 默认标题
defaultGroupTitle?: string;
// 在预览页中展示的最小标题
overviewDepth?: 'h1' | 'h2';
}
```

Expand Down
14 changes: 11 additions & 3 deletions packages/theme-default/src/components/Overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
NormalizedSidebarGroup,
SidebarItem,
SidebarDivider,
type OverViewDepth,
} from '@rspress/shared';
import {
usePageData,
Expand Down Expand Up @@ -34,6 +35,7 @@ export function Overview(props: {
content?: React.ReactNode;
groups?: Group[];
defaultGroupTitle?: string;
overviewDepth?: OverViewDepth;
}) {
const {
siteData,
Expand All @@ -58,7 +60,7 @@ export function Overview(props: {
};
const findItemByRoutePath = (items, routePath, originalItems) => {
for (const item of items) {
if (item.link === routePath) {
if (withBase(item.link) === routePath) {
return [item];
}
if (item.items) {
Expand Down Expand Up @@ -94,11 +96,17 @@ export function Overview(props: {
return item;
}
// do not display overview title in sub pages overview
if (item.link === `${routePath}index` && frontmatter?.overview === true) {
if (
withBase(item.link) === `${routePath}index` &&
frontmatter?.overview === true
) {
return false;
}
const overviewDepth =
item.overviewDepth ?? sidebarGroup?.overviewDepth ?? 'h2';
props?.overviewDepth ??
item.overviewDepth ??
sidebarGroup?.overviewDepth ??
'h2';
const headerDepth = Number(overviewDepth.replace('h', ''));
// sidebar items link without base path
const pageModule = overviewModules.find(m =>
Expand Down

0 comments on commit f719ce6

Please sign in to comment.