From d2642d209fe42cf5249687b059e6e40814a78942 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Fri, 14 Jul 2023 12:58:59 -0500 Subject: [PATCH] fix(#7080): sitemap should only add trailing slash to pages --- .changeset/giant-tomatoes-dream.md | 5 +++++ packages/integrations/sitemap/src/index.ts | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 .changeset/giant-tomatoes-dream.md diff --git a/.changeset/giant-tomatoes-dream.md b/.changeset/giant-tomatoes-dream.md new file mode 100644 index 000000000000..7a8ba593d4cc --- /dev/null +++ b/.changeset/giant-tomatoes-dream.md @@ -0,0 +1,5 @@ +--- +'@astrojs/sitemap': patch +--- + +Ensure trailing slash is only added to page routes diff --git a/packages/integrations/sitemap/src/index.ts b/packages/integrations/sitemap/src/index.ts index 950646247467..132aa7974de2 100644 --- a/packages/integrations/sitemap/src/index.ts +++ b/packages/integrations/sitemap/src/index.ts @@ -1,4 +1,4 @@ -import type { AstroConfig, AstroIntegration } from 'astro'; +import type { AstroConfig, AstroIntegration, RouteType } from 'astro'; import { EnumChangefreq, simpleSitemapAndIndex, @@ -107,7 +107,7 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => { if (config.trailingSlash === 'never') { urls.push(newUrl); - } else if (config.build.format === 'directory' && !newUrl.endsWith('/')) { + } else if (config.build.format === 'directory' && !newUrl.endsWith('/') && r.type === 'page') { urls.push(newUrl + '/'); } else { urls.push(newUrl);