Skip to content

Commit 20fb82d

Browse files
KyleAMathewsclaude
andcommitted
fix: normalize markdown links to work on both GitHub and website
Adds path normalization to MarkdownLink component to handle the difference between GitHub's file-based paths and the website's route-based paths. Links like ./guides/foo.md now work correctly on both platforms. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent fc44ffe commit 20fb82d

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/components/MarkdownLink.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ export function MarkdownLink({
1616

1717
const [hrefWithoutHash, hash] = hrefProp?.split('#') ?? []
1818
let [to] = hrefWithoutHash?.split('.md') ?? []
19+
20+
// Normalize relative paths that work in GitHub to work with our routing structure
21+
// In GitHub: ./guides/foo.md works from docs/overview.md
22+
// In our router: we need ../guides/foo because the current path is /lib/version/docs/overview (not overview/)
23+
if (to?.startsWith('./')) {
24+
// Convert ./path to ../path to account for the fact that we're at /docs/file not /docs/file/
25+
to = '../' + to.slice(2)
26+
}
1927

2028
return (
2129
<Link

0 commit comments

Comments
 (0)