Skip to content

Commit 72d8525

Browse files
committed
fix(web): convert relative .md links to proper /docs/{slug} routes in DocRenderer
Relative links like ./s00a-query-control-plane.md in markdown content were resolving incorrectly when clicked from a chapter page (e.g. /zh/s01/), causing 404s instead of navigating to /zh/docs/s00a-query-control-plane.
1 parent 5dfe67f commit 72d8525

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

web/src/components/docs/doc-renderer.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function renderMarkdown(md: string): string {
2828
return String(result);
2929
}
3030

31-
function postProcessHtml(html: string): string {
31+
function postProcessHtml(html: string, locale: string): string {
3232
// Add language labels to highlighted code blocks
3333
html = html.replace(
3434
/<pre><code class="hljs language-(\w+)">/g,
@@ -61,6 +61,16 @@ function postProcessHtml(html: string): string {
6161
html = html.replace(/<table>/g, '<div class="table-scroll"><table>');
6262
html = html.replace(/<\/table>/g, "</table></div>");
6363

64+
// Transform relative .md links to proper /docs/{slug} routes
65+
// e.g. ./s00a-query-control-plane.md -> /{locale}/docs/s00a-query-control-plane
66+
html = html.replace(
67+
/href="\.\/([^"]+\.md)"/g,
68+
(_, filename) => {
69+
const slug = filename.replace(/\.md$/, "");
70+
return `href="/${locale}/docs/${slug}"`;
71+
}
72+
);
73+
6474
return html;
6575
}
6676

@@ -93,8 +103,8 @@ export function DocRenderer({ version, slug }: DocRendererProps) {
93103

94104
const html = useMemo(() => {
95105
const raw = renderMarkdown(doc.content);
96-
return postProcessHtml(raw);
97-
}, [doc.content]);
106+
return postProcessHtml(raw, locale);
107+
}, [doc.content, locale]);
98108

99109
return (
100110
<div className="py-4">

0 commit comments

Comments
 (0)