Respect the site's trailingSlash config when building URLs#2
Open
bimsonz wants to merge 2 commits into
Open
Conversation
buildPageUrl and generateCanonical hardcoded a trailing slash, so every URL the plugin emits (sitemap schema/map, llms.txt, canonical, hreflang, IndexNow) ended in a slash. That matches Astro's default, but not a site configured with trailingSlash: 'never' — notably headless consumers whose front-end serves bare URLs, where the sitemap/canonical then advertise URLs that don't match the site. Add a shared applyTrailingSlash(path, mode) that honours the site's policy, taken from ctx.site.trailingSlash (Astro's trailingSlash, newly exposed by emdash), and thread it through every URL/canonical call site. Backward-compatible: the default, 'always' and 'ignore' keep the trailing slash; only 'never' strips it. Depends on emdash exposing ctx.site.trailingSlash.
11 tasks
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.
Problem
buildPageUrlandgenerateCanonicalhardcode a trailing slash, so every URL the plugin emits — theschema/mapsitemap feed,llms.txt, canonical, hreflang, and IndexNow — ends in/. That matches Astro's default (trailingSlash: 'ignore'/'always'), but not a site configured withtrailingSlash: 'never'. It especially affects headless consumers, whose front-end serves bare URLs like/blog/post— the plugin then advertises/blog/post/, which the site doesn't serve.Change
applyTrailingSlash(path, mode)helper and thread atrailingSlashpolicy through every URL/canonical call site:urls.ts,canonical.ts,schema/endpoints.ts,hreflang.ts,llms.ts,indexnow.ts,metadata.ts.ctx.site.trailingSlash— Astro'strailingSlash, exposed by emdash in the companion PR below.'always', and'ignore'keep the trailing slash; only'never'strips it. Existing Astro-served sites are unchanged.applyTrailingSlash+buildPageUrlunder each policy, plusschema/map(listSchemaEntries) asserting bare URLs whentrailingSlash: 'never'.Dependency
Requires emdash exposing
ctx.site.trailingSlash— companion PR: emdash-cms/emdash#2122. Until it lands,ctx.site.trailingSlashisundefinedat runtime and behaviour is unchanged, so either merge order is safe.