Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use directory-style path formatting with build.format: 'preserve' #1913

Merged
merged 2 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading