From dd775bec9878c5e2eaab2babba51cf59c5d4e818 Mon Sep 17 00:00:00 2001 From: Niklas van Schrick Date: Thu, 21 Dec 2023 22:29:39 +0100 Subject: [PATCH] Fix relative links on index pages --- astro.config.mjs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/astro.config.mjs b/astro.config.mjs index 162f30e..01b1d26 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -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,