From 5d032249b3d936f17b077e09136c1db38759684b Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Thu, 19 Dec 2024 09:49:35 -0700 Subject: [PATCH] fix: dont strip trailing index from links unless it is the full segment --- packages/starlight-links-validator/libs/remark.ts | 2 +- .../src/content/docs/a-page-that-ends-with-index.md | 5 +++++ .../tests/fixtures/valid-links/src/content/docs/index.md | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 packages/starlight-links-validator/tests/fixtures/valid-links/src/content/docs/a-page-that-ends-with-index.md diff --git a/packages/starlight-links-validator/libs/remark.ts b/packages/starlight-links-validator/libs/remark.ts index 40a8ab4..0199694 100644 --- a/packages/starlight-links-validator/libs/remark.ts +++ b/packages/starlight-links-validator/libs/remark.ts @@ -178,7 +178,7 @@ function normalizeFilePath(base: string, srcDir: URL, filePath?: string) { const path = nodePath .relative(nodePath.join(fileURLToPath(srcDir), 'content/docs'), filePath) .replace(/\.\w+$/, '') - .replace(/index$/, '') + .replace(/(^|[/\\])index$/, '$1') .replace(/[/\\]?$/, '/') .split(/[/\\]/) .map((segment) => slug(segment)) diff --git a/packages/starlight-links-validator/tests/fixtures/valid-links/src/content/docs/a-page-that-ends-with-index.md b/packages/starlight-links-validator/tests/fixtures/valid-links/src/content/docs/a-page-that-ends-with-index.md new file mode 100644 index 0000000..101bdac --- /dev/null +++ b/packages/starlight-links-validator/tests/fixtures/valid-links/src/content/docs/a-page-that-ends-with-index.md @@ -0,0 +1,5 @@ +--- +title: A page that ends with index +--- + +Content diff --git a/packages/starlight-links-validator/tests/fixtures/valid-links/src/content/docs/index.md b/packages/starlight-links-validator/tests/fixtures/valid-links/src/content/docs/index.md index e9b7dc8..7e51eb0 100644 --- a/packages/starlight-links-validator/tests/fixtures/valid-links/src/content/docs/index.md +++ b/packages/starlight-links-validator/tests/fixtures/valid-links/src/content/docs/index.md @@ -19,6 +19,8 @@ title: Index - [An MDX nested page](/guides/example) - [An MDX nested page](/guides/example/) +- [A page that ends with index](/a-page-that-ends-with-index) + # More links - [Link to hash in this page](#some-links)