From cc1dae55c8bbf0a7d862e227f7daed138c485be4 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Mon, 6 Dec 2021 16:50:30 -0600 Subject: [PATCH] fix(#2129): exclude 404 from sitemap (#2137) * fix(#2129): exclude 404 from sitemap * chore(lint): Prettier fix * chore: trigger ci Co-authored-by: GitHub Action --- .changeset/angry-pillows-accept.md | 5 +++++ packages/astro/src/core/ssr/sitemap.ts | 4 +++- packages/astro/test/astro-sitemap-rss.test.js | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 .changeset/angry-pillows-accept.md diff --git a/.changeset/angry-pillows-accept.md b/.changeset/angry-pillows-accept.md new file mode 100644 index 000000000..8cd933d1e --- /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 9de7ea6e6..facf49b1f 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 33a6621eb..c02b9282b 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` ); }); });