From a912071dab4929338a831020890b699fc400cd77 Mon Sep 17 00:00:00 2001 From: Andrew Anderson Date: Mon, 19 Oct 2026 11:51:38 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20strip=20.mdx=20as=20well?= =?UTF-8?q?=20as=20.md=20when=20building=20sync-sibling-docs=20route=20map?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit rewriteLinks built the synced-route map with target.replace(/\.md$/i, ''), so a page synced with an .mdx target produced /docs//.mdx. Match .mdx? and add a rewriteLinks test for an .mdx target. Signed-off-by: Andrew Anderson --- changelog.d/fixed-355-sync-sibling-docs-mdx-route.md | 4 ++++ scripts/sync-sibling-docs.test.ts | 12 ++++++++++++ scripts/sync-sibling-docs.ts | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 changelog.d/fixed-355-sync-sibling-docs-mdx-route.md diff --git a/changelog.d/fixed-355-sync-sibling-docs-mdx-route.md b/changelog.d/fixed-355-sync-sibling-docs-mdx-route.md new file mode 100644 index 0000000..f092ca0 --- /dev/null +++ b/changelog.d/fixed-355-sync-sibling-docs-mdx-route.md @@ -0,0 +1,4 @@ +- `scripts/sync-sibling-docs.ts` now strips `.mdx` as well as `.md` when + mapping a synced page to its `/docs//…` route, so links to pages + synced as MDX no longer resolve to `/docs//.mdx` + (hivecommons/docs#355). diff --git a/scripts/sync-sibling-docs.test.ts b/scripts/sync-sibling-docs.test.ts index d7a1767..8afa9e9 100644 --- a/scripts/sync-sibling-docs.test.ts +++ b/scripts/sync-sibling-docs.test.ts @@ -116,6 +116,18 @@ describe("rewriteLinks", () => { ); }); + it("strips .mdx as well as .md from a synced target's route", () => { + const mdx: ProjectSync = { + ...spek, + files: [ + { source: "docs/guide.md", target: "guide.mdx", required: false }, + ], + }; + expect(rewriteLinks("[g](docs/guide.md#top)", mdx)).toBe( + "[g](/docs/spektacular/guide#top)" + ); + }); + it("matches synced pages case-insensitively", () => { expect(rewriteLinks("[kb](Docs/Knowledge-Base.MD)", spek)).toBe( "[kb](/docs/spektacular/knowledge-base)" diff --git a/scripts/sync-sibling-docs.ts b/scripts/sync-sibling-docs.ts index 1b53681..d36e95b 100644 --- a/scripts/sync-sibling-docs.ts +++ b/scripts/sync-sibling-docs.ts @@ -423,7 +423,7 @@ export function rewriteLinks( for (const s of p.files) { syncedRoutes.set( s.source.toLowerCase(), - `/docs/${p.project}/${s.target.replace(/\.md$/i, "")}` + `/docs/${p.project}/${s.target.replace(/\.mdx?$/i, "")}` ); } const r = f ? fileRepo(p, f) : p;