Skip to content

Commit 6f272df

Browse files
authored
feat(ssg-md): add SSG-MD support to OverviewGroup and FallbackHeading components (Vibe Kanban) (#2966)
1 parent 8b58028 commit 6f272df

File tree

3 files changed

+58
-54
lines changed

3 files changed

+58
-54
lines changed

packages/core/src/theme/components/FallbackHeading/index.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export function FallbackHeading({
2828
level: 1 | 2 | 3 | 4 | 5 | 6;
2929
title: string;
3030
}) {
31+
if (process.env.__SSR_MD__) {
32+
return <>{`${'#'.repeat(level)} ${title}\n\n`}</>;
33+
}
34+
3135
const titleSlug = title && slug(title.trim());
3236

3337
const Element = useMemo(() => {

packages/core/src/theme/components/Overview/index.tsx

Lines changed: 8 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type {
66
} from '@rspress/core';
77
import {
88
isEqualPath,
9-
routePathToMdPath,
109
useI18n,
1110
usePageData,
1211
useSidebar,
@@ -26,58 +25,6 @@ import {
2625
import './index.scss';
2726
import { findItemByRoutePath } from './utils';
2827

29-
function OverviewMarkdown({
30-
title,
31-
groups,
32-
}: {
33-
title: string;
34-
groups: Group[];
35-
}) {
36-
const lines: string[] = [];
37-
38-
lines.push(`# ${title}`);
39-
lines.push('');
40-
41-
for (const group of groups) {
42-
if (group.name) {
43-
lines.push(`## ${group.name}`);
44-
lines.push('');
45-
}
46-
47-
for (const item of group.items) {
48-
const itemTitle = item.link
49-
? `[${item.text}](${routePathToMdPath(item.link)})`
50-
: `**${item.text}**`;
51-
lines.push(`### ${itemTitle}`);
52-
lines.push('');
53-
54-
// Render headers as a list
55-
if (item.headers && item.headers.length > 0) {
56-
for (const header of item.headers) {
57-
const headerLink = item.link
58-
? `[${header.text}](${routePathToMdPath(item.link)}#${header.id})`
59-
: header.text;
60-
lines.push(`- ${headerLink}`);
61-
}
62-
lines.push('');
63-
}
64-
65-
// Render custom items as a list
66-
if (item.items && item.items.length > 0) {
67-
for (const subItem of item.items) {
68-
const subItemLink = subItem.link
69-
? `[${subItem.text}](${routePathToMdPath(subItem.link)})`
70-
: subItem.text;
71-
lines.push(`- ${subItemLink}`);
72-
}
73-
lines.push('');
74-
}
75-
}
76-
}
77-
78-
return <>{lines.join('\n')}</>;
79-
}
80-
8128
// Utility function to normalize text for search
8229
const normalizeText = (s: string) => s.toLowerCase().replace(/-/g, ' ');
8330

@@ -294,7 +241,14 @@ export function Overview(props: {
294241
const overviewTitle = title || 'Overview';
295242

296243
if (process.env.__SSR_MD__) {
297-
return <OverviewMarkdown title={overviewTitle} groups={groups} />;
244+
return (
245+
<>
246+
<FallbackHeading level={1} title={overviewTitle} />
247+
{groups.map(group => (
248+
<OverviewGroup key={group?.name} group={group} />
249+
))}
250+
</>
251+
);
298252
}
299253

300254
return (

packages/core/src/theme/components/OverviewGroup/index.tsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,52 @@
11
import { Link, renderInlineMarkdown } from '@theme';
22
import './index.scss';
33
import type { Header } from '@rspress/core';
4+
import { routePathToMdPath } from '@rspress/core/runtime';
45
import { FallbackHeading, SvgWrapper } from '@theme';
56
import { useMemo } from 'react';
67
import IconPlugin from './icons/plugin.svg';
78

9+
function OverviewGroupMarkdown({ group }: { group: Group }) {
10+
const lines: string[] = [];
11+
12+
if (group.name) {
13+
lines.push(`## ${group.name}`);
14+
lines.push('');
15+
}
16+
17+
for (const item of group.items) {
18+
const itemTitle = item.link
19+
? `[${item.text}](${routePathToMdPath(item.link)})`
20+
: `**${item.text}**`;
21+
lines.push(`### ${itemTitle}`);
22+
lines.push('');
23+
24+
// Render headers as a list
25+
if (item.headers && item.headers.length > 0) {
26+
for (const header of item.headers) {
27+
const headerLink = item.link
28+
? `[${header.text}](${routePathToMdPath(item.link)}#${header.id})`
29+
: header.text;
30+
lines.push(`- ${headerLink}`);
31+
}
32+
lines.push('');
33+
}
34+
35+
// Render custom items as a list
36+
if (item.items && item.items.length > 0) {
37+
for (const subItem of item.items) {
38+
const subItemLink = subItem.link
39+
? `[${subItem.text}](${routePathToMdPath(subItem.link)})`
40+
: subItem.text;
41+
lines.push(`- ${subItemLink}`);
42+
}
43+
lines.push('');
44+
}
45+
}
46+
47+
return <>{lines.join('\n')}</>;
48+
}
49+
850
export interface GroupItem {
951
text: string;
1052
link: string;
@@ -20,6 +62,10 @@ export interface Group {
2062
}
2163

2264
export const OverviewGroup = ({ group }: { group: Group }) => {
65+
if (process.env.__SSR_MD__) {
66+
return <OverviewGroupMarkdown group={group} />;
67+
}
68+
2369
const { itemsWithContent, itemsWithoutContent } = useMemo(() => {
2470
// Separate items into those with content and those without
2571
const itemsWithContent = group.items.filter(

0 commit comments

Comments
 (0)