Skip to content

Commit

Permalink
[pkg/sitemap-ext]: Fixes trailingSlash handling for SSR dynamic routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Fryuni committed Apr 2, 2024
1 parent b25ba12 commit 0d0033c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/shaggy-bobcats-type.md
Original file line number Diff line number Diff line change
@@ -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
6 changes: 5 additions & 1 deletion packages/sitemap-ext/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}
},
};
Expand Down

0 comments on commit 0d0033c

Please sign in to comment.