From 0d0033c27097558d6c3d0eb0ec9c1d3a4670247f Mon Sep 17 00:00:00 2001 From: Luiz Ferraz Date: Tue, 2 Apr 2024 18:18:24 -0300 Subject: [PATCH] [pkg/sitemap-ext]: Fixes `trailingSlash` handling for SSR dynamic routes --- .changeset/shaggy-bobcats-type.md | 5 +++++ packages/sitemap-ext/index.ts | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 .changeset/shaggy-bobcats-type.md diff --git a/.changeset/shaggy-bobcats-type.md b/.changeset/shaggy-bobcats-type.md new file mode 100644 index 00000000..cf3e6906 --- /dev/null +++ b/.changeset/shaggy-bobcats-type.md @@ -0,0 +1,5 @@ +--- +"@inox-tools/sitemap-ext": patch +--- + +Fixes generation of dynamic SSR URLs to behave the same as the official sitemap integration regarding `trailingSlash` configuration diff --git a/packages/sitemap-ext/index.ts b/packages/sitemap-ext/index.ts index 92fabe6a..ad54f8a8 100644 --- a/packages/sitemap-ext/index.ts +++ b/packages/sitemap-ext/index.ts @@ -70,11 +70,14 @@ export default defineIntegration({ const extraPages: string[] = [...(_externalPages ?? [])]; + let trailingSlash = false; + let baseUrl!: URL; return { 'astro:config:setup': (params) => { const { defineRouteConfig, logger, config } = params; + trailingSlash = config.trailingSlash !== 'never'; if (hasIntegration(params, { name: '@astrojs/sitemap' })) { throw new AstroError( @@ -169,7 +172,8 @@ export default defineIntegration({ } for (const page of extraPagesSet) { - extraPages.push(new URL(page, baseUrl).toString()); + const url = trimSlashes(new URL(page, baseUrl).toString()); + extraPages.push(trailingSlash ? url + '/' : url); } }, };