fix(seo): preserve path separators when encoding sitemap URLs#677
Draft
drudge wants to merge 1 commit intoemdash-cms:mainfrom
Draft
fix(seo): preserve path separators when encoding sitemap URLs#677drudge wants to merge 1 commit intoemdash-cms:mainfrom
drudge wants to merge 1 commit intoemdash-cms:mainfrom
Conversation
|
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/blocks
@emdash-cms/cloudflare
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
`encodeURIComponent(slug)` turns multi-segment slugs like `faq/products`
into `faq%2Fproducts`, producing broken URLs in the sitemap. Add an
`encodePathSegments` helper that splits on `/`, `encodeURIComponent`s
each segment, and rejoins — so slashes used as path separators stay
literal while other reserved characters are still escaped.
Applied to the three places the route composes paths from user-
controlled identifiers: `{slug}` / `{id}` placeholder substitutions
and the default `/{collection}/{slug}` fallback.
52f1844 to
0f9d22d
Compare
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
The per-collection sitemap route calls
encodeURIComponenton slugs, ids, and collection names when composing URLs. For multi-segment slugs likefaq/products, that turns/into%2Fand produces broken URLs like/faq%2Fproductsin the sitemap output.Add an
encodePathSegmentshelper that splits on/,encodeURIComponents each segment, and rejoins — so path separators stay literal while other reserved characters continue to be escaped.Changes
packages/core/src/astro/routes/sitemap-[collection].xml.tsencodePathSegmentshelper.{slug}and{id}placeholder substitutions inurl_pattern, plus the default/{collection}/{slug}fallback.Test plan
pnpm --filter emdash test -- tests/integration/seo/seo.test.ts).url_pattern: /{slug}and slugs likefaq/products: output ishttps://example.com/faq/products, nothttps://example.com/faq%2Fproducts.