From 54ee3d34e9a41264f0d865e6ea7cc75d2c7ca95a 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 825e8e3060e98..bf438b713d11c 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;