diff --git a/.changeset/angry-pillows-accept.md b/.changeset/angry-pillows-accept.md new file mode 100644 index 0000000000..8cd933d1ed --- /dev/null +++ b/.changeset/angry-pillows-accept.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Exclude 404 pages from sitemap generation diff --git a/packages/astro/src/core/ssr/sitemap.ts b/packages/astro/src/core/ssr/sitemap.ts index 9de7ea6e66..facf49b1f4 100644 --- a/packages/astro/src/core/ssr/sitemap.ts +++ b/packages/astro/src/core/ssr/sitemap.ts @@ -4,7 +4,9 @@ export function generateSitemap(pages: string[]): string { // TODO: find way to exclude pages from sitemap - const urls = [...pages]; // copy just in case original copy is needed + // copy just in case original copy is needed + // make sure that 404 page is excluded + const urls = [...pages].filter((url) => !url.endsWith('/404/index.html')); urls.sort((a, b) => a.localeCompare(b, 'en', { numeric: true })); // sort alphabetically so sitemap is same each time let sitemap = ``; for (const url of urls) { diff --git a/packages/astro/test/astro-sitemap-rss.test.js b/packages/astro/test/astro-sitemap-rss.test.js index 33a6621eb4..c02b9282ba 100644 --- a/packages/astro/test/astro-sitemap-rss.test.js +++ b/packages/astro/test/astro-sitemap-rss.test.js @@ -29,7 +29,7 @@ describe('Sitemaps', () => { it('Generates Sitemap correctly', async () => { let sitemap = await fixture.readFile('/sitemap.xml'); expect(sitemap).to.equal( - `https://astro.build/404/index.htmlhttps://astro.build/episode/fazers/index.htmlhttps://astro.build/episode/rap-snitch-knishes/index.htmlhttps://astro.build/episode/rhymes-like-dimes/index.htmlhttps://astro.build/episodes/index.html\n` + `https://astro.build/episode/fazers/index.htmlhttps://astro.build/episode/rap-snitch-knishes/index.htmlhttps://astro.build/episode/rhymes-like-dimes/index.htmlhttps://astro.build/episodes/index.html\n` ); }); });