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;