Skip to content

Commit

Permalink
Fix relative links on index pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Taucher2003 committed Dec 21, 2023
1 parent 5f456ea commit dd775be
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ const transformLocalLinks = () => {

transform(src, id) {
if (id.endsWith('.md') || id.endsWith('.mdx')) {
const directory = id.endsWith('index.md') || id.endsWith('index.mdx') ? '' : '../';

const code = src
.replaceAll(/\[([^\]]+?)]\(([^)]+?)\.mdx?\)/g, "[$1](../$2/)")
.replaceAll(/href=\\"([^"]+?)\.mdx?\\"/g, "href=\\\"../$1/\\\"")
.replaceAll(/href: "([^"]+?)\.mdx?"/g, "href: \"../$1/\"");
.replaceAll(/\[([^\]]+?)]\(([^)]+?)\.mdx?\)/g, `[$1](${directory}$2/)`)
.replaceAll(/href=\\"([^"]+?)\.mdx?\\"/g, `href=\\"${directory}$1/\\"`)
.replaceAll(/href: "([^"]+?)\.mdx?"/g, `href: "${directory}$1/"`);

return {
code: code,
Expand Down

0 comments on commit dd775be

Please sign in to comment.