From 0963db1b6a73e427f0bc1207b6a17ac37ff6e589 Mon Sep 17 00:00:00 2001 From: Chris Swithinbank Date: Tue, 21 May 2024 17:14:18 +0200 Subject: [PATCH 1/2] Use `directory`-style path formatting with `build.format: 'preserve'` Fixes #1781 --- packages/starlight/utils/createPathFormatter.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/starlight/utils/createPathFormatter.ts b/packages/starlight/utils/createPathFormatter.ts index f4db6f7a02c..09922997915 100644 --- a/packages/starlight/utils/createPathFormatter.ts +++ b/packages/starlight/utils/createPathFormatter.ts @@ -12,15 +12,18 @@ interface FormatPathOptions { trailingSlash?: AstroConfig['trailingSlash']; } +const defaultFormatStrategy = { + addBase: pathWithBase, + handleExtension: (href: string) => stripHtmlExtension(href), +}; + const formatStrategies = { file: { addBase: fileWithBase, handleExtension: (href: string) => ensureHtmlExtension(href), }, - directory: { - addBase: pathWithBase, - handleExtension: (href: string) => stripHtmlExtension(href), - }, + directory: defaultFormatStrategy, + preserve: defaultFormatStrategy, }; const trailingSlashStrategies = { @@ -34,7 +37,6 @@ function formatPath( href: string, { format = 'directory', trailingSlash = 'ignore' }: FormatPathOptions ) { - // @ts-expect-error — TODO: add support for `preserve` (https://github.com/withastro/starlight/issues/1781) const formatStrategy = formatStrategies[format]; const trailingSlashStrategy = trailingSlashStrategies[trailingSlash]; From 33df8c0f66716905bdc7c13c84b1f0ebc4c09fe1 Mon Sep 17 00:00:00 2001 From: Chris Swithinbank Date: Tue, 21 May 2024 17:36:17 +0200 Subject: [PATCH 2/2] Add changeset --- .changeset/curvy-pots-ring.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/curvy-pots-ring.md diff --git a/.changeset/curvy-pots-ring.md b/.changeset/curvy-pots-ring.md new file mode 100644 index 00000000000..488b0cfd012 --- /dev/null +++ b/.changeset/curvy-pots-ring.md @@ -0,0 +1,5 @@ +--- +'@astrojs/starlight': patch +--- + +Fixes support for Astro’s `build: { format: 'preserve' }` configuration option