From 7f6c35f6360e05b146b2f10624a43c03408e74e8 Mon Sep 17 00:00:00 2001 From: Mani Gandham Date: Wed, 1 Sep 2021 15:02:11 -0700 Subject: [PATCH] skip 404.html pages in sitemap generation (#1287) * skip 404.html pages in sitemap generation * update path check for 404 --- packages/astro/src/build/sitemap.ts | 4 ++-- .../astro/test/fixtures/astro-rss/src/pages/404.astro | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 packages/astro/test/fixtures/astro-rss/src/pages/404.astro diff --git a/packages/astro/src/build/sitemap.ts b/packages/astro/src/build/sitemap.ts index bca69dd8a..d1e15636f 100644 --- a/packages/astro/src/build/sitemap.ts +++ b/packages/astro/src/build/sitemap.ts @@ -1,5 +1,4 @@ import type { BuildOutput } from '../@types/astro'; - import { canonicalURL } from './util.js'; /** Construct sitemap.xml given a set of URLs */ @@ -7,11 +6,12 @@ export function generateSitemap(buildState: BuildOutput, site: string): string { const uniqueURLs = new Set(); // TODO: find way to respect URLs here - // TODO: find way to exclude pages from sitemap + // TODO: find way to exclude pages from sitemap (currently only skips 404 pages) // look through built pages, only add HTML for (const id of Object.keys(buildState)) { if (buildState[id].contentType !== 'text/html') continue; + if (id === '/404.html') continue; uniqueURLs.add(canonicalURL(id, site).href); } diff --git a/packages/astro/test/fixtures/astro-rss/src/pages/404.astro b/packages/astro/test/fixtures/astro-rss/src/pages/404.astro new file mode 100644 index 000000000..23df09841 --- /dev/null +++ b/packages/astro/test/fixtures/astro-rss/src/pages/404.astro @@ -0,0 +1,10 @@ +--- +--- + + + 404 + + + 404 + +