fix: correct Astro.url.pathname for non-index pages with build.format: 'preserve' - #17560
Open
astrobot-houston wants to merge 2 commits into
Open
fix: correct Astro.url.pathname for non-index pages with build.format: 'preserve'#17560astrobot-houston wants to merge 2 commits into
Astro.url.pathname for non-index pages with build.format: 'preserve'#17560astrobot-houston wants to merge 2 commits into
Conversation
… preserve When using build.format: 'preserve', non-index pages (e.g. about-me.astro) output as flat .html files (about-me.html), but Astro.url.pathname incorrectly returned a trailing-slash path (/about-me/) instead of the .html path (/about-me.html). The root cause was in getUrlForPath() which unconditionally grouped 'preserve' with 'directory' format for URL ending computation. Now 'preserve' splits behavior based on route.isIndex: index routes use directory-style URLs (trailing slash) and non-index routes use file-style URLs (.html extension), matching the pattern already used by getOutFolder(), getOutFile(), and getOutputFilename(). Fixes #17556
… preserve When using build.format: 'preserve', non-index pages (e.g. about-me.astro) output as flat .html files (about-me.html), but Astro.url.pathname incorrectly returned a trailing-slash path (/about-me/) instead of the .html path (/about-me.html). The root cause was in getUrlForPath() which unconditionally grouped 'preserve' with 'directory' format for URL ending computation. Now 'preserve' splits behavior based on route.isIndex: index routes use directory-style URLs (trailing slash) and non-index routes use file-style URLs (.html extension), matching the pattern already used by getOutFolder(), getOutFile(), and getOutputFilename(). Fixes #17556
1 task
🦋 Changeset detectedLatest commit: 6676795 The changes in this PR will be included in the next version bump. This PR includes changesets to release 399 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a bug where
Astro.url.pathnamereturned the wrong value for non-index pages when usingbuild.format: 'preserve'.Closes #17556
What was wrong
With
build.format: 'preserve', the rest of the build pipeline (output filename generation,getOutFolder,getOutFile) correctly splits behavior based onroute.isIndex:src/pages/about-me.astro) →dist/about-me.html(likefileformat)src/pages/blog/index.astro) →dist/blog/index.html(likedirectoryformat)But
getUrlForPath()ingenerate.ts— which computes theURLobject that becomesAstro.urlduring static builds — unconditionally treated'preserve'like'directory', giving everypreserveroute a trailing-slash pathname. This meant a page built toabout-me.htmlreportedAstro.url.pathnameas/about-me/instead of/about-me.html.Fix
Introduce an
effectiveFormatthat resolves'preserve'to'file'or'directory'based onroute.isIndex, matching the behavior already used throughout the rest of the build pipeline.Testing
Added a
preservetest suite inpackages/astro/test/page-format.test.tscovering:.htmlpathname (e.g./about-me.html)/blog/)All existing tests continue to pass.