Skip to content

Commit b8d75f1

Browse files
committed
fix: site base url
1 parent f737d4f commit b8d75f1

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

components/Content.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,37 @@ import "npm:[email protected]/components/prism-typescript.js";
55
export function Content({
66
markdown,
77
baseUrl,
8+
siteBaseUrl,
89
}: {
910
markdown: string;
1011
baseUrl?: string;
12+
siteBaseUrl?: string;
1113
}) {
12-
const html = render(markdown, { baseUrl });
14+
let html = render(markdown, { baseUrl });
15+
16+
// If siteBaseUrl is provided, transform relative links to use site URLs instead of raw GitHub URLs
17+
if (siteBaseUrl && baseUrl) {
18+
// Replace links that point to the raw GitHub URL with site URLs
19+
const githubRawPattern = new RegExp(
20+
baseUrl.replace(/[.*+?^${}()|[\]\\]/g, "\\$&").replace(/[^/]+$/, ""),
21+
"g",
22+
);
23+
html = html.replace(
24+
/href="https:\/\/raw\.githubusercontent\.com\/[^"]+"/g,
25+
(match: string) => {
26+
// Extract the path from the raw GitHub URL
27+
const urlMatch = match.match(
28+
/href="https:\/\/raw\.githubusercontent\.com\/[^/]+\/[^/]+\/[^/]+\/(.+?)"/,
29+
);
30+
if (urlMatch && urlMatch[1]) {
31+
const path = urlMatch[1];
32+
return `href="${siteBaseUrl}${path}"`;
33+
}
34+
return match;
35+
},
36+
);
37+
}
38+
1339
return (
1440
<>
1541
<div

routes/std/[...path].tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ export default async function StdPage(props: PageProps<never>) {
299299
<MarkdownContent
300300
markdown={readmePreview.content}
301301
baseUrl={`https://raw.githubusercontent.com/${OWNER}/${REPO}/${BRANCH}/${readmePreview.path}`}
302+
siteBaseUrl="/std/"
302303
/>
303304
</div>
304305
</div>
@@ -334,6 +335,7 @@ export default async function StdPage(props: PageProps<never>) {
334335
<MarkdownContent
335336
markdown={content || ""}
336337
baseUrl={`https://raw.githubusercontent.com/${OWNER}/${REPO}/${BRANCH}/${path}`}
338+
siteBaseUrl="/std/"
337339
/>
338340
</div>
339341
) :

0 commit comments

Comments
 (0)