From 261600aa28f14f825b58ea490ddf55cf46945df1 Mon Sep 17 00:00:00 2001 From: AnnsAnn Date: Fri, 10 Oct 2025 12:11:35 +0200 Subject: [PATCH] doc/starlight: add route middleware to fix edit link --- doc/starlight/astro.config.mjs | 1 + doc/starlight/src/routeData.ts | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 doc/starlight/src/routeData.ts diff --git a/doc/starlight/astro.config.mjs b/doc/starlight/astro.config.mjs index 975ec95c16e4..24c3fca384d1 100644 --- a/doc/starlight/astro.config.mjs +++ b/doc/starlight/astro.config.mjs @@ -177,6 +177,7 @@ export default defineConfig({ replacesTitle: true, }, plugins: [starlightImageZoom()], + routeMiddleware: "./src/routeData.ts", editLink: { baseUrl: "https://github.com/RIOT-OS/RIOT/tree/master/doc/guides", }, diff --git a/doc/starlight/src/routeData.ts b/doc/starlight/src/routeData.ts new file mode 100644 index 000000000000..545eca47e2bc --- /dev/null +++ b/doc/starlight/src/routeData.ts @@ -0,0 +1,23 @@ +import { defineRouteMiddleware } from "@astrojs/starlight/route-data"; + +/** + * Since we currently use a symlink to comply with the (broken) + * docs folder scanning of starlight, this will break the edit + * link since, while technically correct, our symlink will be + * shown as github.com/RIOT-OS/RIOT/doc/guides/src/content/docs/foobar + * Since github can't parse symlinks, we need to modify the editUrl + * through a route middleware in order for the edit link to still function + * + * As soon as base directory changes get fixed, this should be removed + * again! See: https://github.com/withastro/starlight/pull/3332 + */ +export const onRequest = defineRouteMiddleware((context) => { + const { starlightRoute } = context.locals; + + if (starlightRoute.editUrl) { + starlightRoute.editUrl = new URL( + starlightRoute.editUrl.href.replace("src/content/docs/", ""), + starlightRoute.editUrl, + ); + } +});