From 33dd8ca40f5c763ab16aeffd3ca5e92fa037a27e Mon Sep 17 00:00:00 2001 From: Atila Fassina Date: Wed, 15 Mar 2023 10:38:11 +0100 Subject: [PATCH] add logic to respect "directory" build format --- packages/integrations/sitemap/src/index.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/packages/integrations/sitemap/src/index.ts b/packages/integrations/sitemap/src/index.ts index f6ddbe7b37a67..0814ae0e1a3d8 100644 --- a/packages/integrations/sitemap/src/index.ts +++ b/packages/integrations/sitemap/src/index.ts @@ -95,8 +95,16 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => { * because `finalSiteUrl` always has trailing slash */ const path = finalSiteUrl.pathname + r.generate(r.pathname).substring(1); - const newUrl = new URL(path, finalSiteUrl).href; - urls.push(newUrl); + + let newUrl = new URL(path, finalSiteUrl).href; + + if (config.trailingSlash === 'never') { + urls.push(newUrl); + } else if (config.build.format === 'directory' && !newUrl.endsWith('/')) { + urls.push(newUrl + '/'); + } else { + urls.push(newUrl); + } } return urls;