Skip to content

Commit

Permalink
Use directory-style path formatting with build.format: 'preserve' (
Browse files Browse the repository at this point in the history
  • Loading branch information
delucis authored May 22, 2024
1 parent cb44095 commit 7ebe8f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/curvy-pots-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/starlight': patch
---

Fixes support for Astro’s `build: { format: 'preserve' }` configuration option
12 changes: 7 additions & 5 deletions packages/starlight/utils/createPathFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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];

Expand Down

0 comments on commit 7ebe8f7

Please sign in to comment.