Skip to content

Commit 1d211dc

Browse files
authored
fix(tui): rewrite relative README links to GitHub URLs on landing site (#25)
1 parent acc082d commit 1d211dc

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

packages/landing/src/pages/index.astro

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,33 @@ const __dirname = dirname(__filename);
1414
const readmePath = join(__dirname, '../../../../README.md');
1515
const readmeContent = readFileSync(readmePath, 'utf-8');
1616
17+
const GITHUB_BLOB =
18+
'https://github.com/junhoyeo/contrabass/blob/main/';
19+
const GITHUB_TREE =
20+
'https://github.com/junhoyeo/contrabass/tree/main/';
21+
22+
function isRelative(href: string): boolean {
23+
return !!href && !href.startsWith('http') && !href.startsWith('#') && !href.startsWith('mailto:');
24+
}
25+
1726
const parser = new Marked(
1827
markedHighlight({
1928
langPrefix: 'hljs language-',
2029
highlight(code, lang) {
2130
const language = lang && hljs.getLanguage(lang) ? lang : 'plaintext';
2231
return hljs.highlight(code, { language }).value;
2332
},
24-
})
33+
}),
34+
{
35+
walkTokens(token) {
36+
if (token.type === 'link' && isRelative(token.href)) {
37+
token.href = (token.href.endsWith('/') ? GITHUB_TREE : GITHUB_BLOB) + token.href;
38+
}
39+
if (token.type === 'image' && isRelative(token.href)) {
40+
token.href = GITHUB_BLOB + token.href;
41+
}
42+
},
43+
},
2544
);
2645
2746
const htmlContent = parser.parse(readmeContent);

0 commit comments

Comments
 (0)