summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Nate Moore <natemoo-re@users.noreply.github.com> 2021-12-06 16:50:30 -0600
committerGravatar GitHub <noreply@github.com> 2021-12-06 16:50:30 -0600
commitcc1dae55c8bbf0a7d862e227f7daed138c485be4 (patch)
treea28c2c91fea3a598c534127bc4004dd43b628b8c
parentddac9777487b14acc24080a70dad78d120ef6d9b (diff)
downloadastro-cc1dae55c8bbf0a7d862e227f7daed138c485be4.tar.gz
astro-cc1dae55c8bbf0a7d862e227f7daed138c485be4.tar.zst
astro-cc1dae55c8bbf0a7d862e227f7daed138c485be4.zip
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 <github-action@users.noreply.github.com>
-rw-r--r--.changeset/angry-pillows-accept.md5
-rw-r--r--packages/astro/src/core/ssr/sitemap.ts4
-rw-r--r--packages/astro/test/astro-sitemap-rss.test.js2
3 files changed, 9 insertions, 2 deletions
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 = `<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">`;
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(
- `<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>https://astro.build/404/index.html</loc></url><url><loc>https://astro.build/episode/fazers/index.html</loc></url><url><loc>https://astro.build/episode/rap-snitch-knishes/index.html</loc></url><url><loc>https://astro.build/episode/rhymes-like-dimes/index.html</loc></url><url><loc>https://astro.build/episodes/index.html</loc></url></urlset>\n`
+ `<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>https://astro.build/episode/fazers/index.html</loc></url><url><loc>https://astro.build/episode/rap-snitch-knishes/index.html</loc></url><url><loc>https://astro.build/episode/rhymes-like-dimes/index.html</loc></url><url><loc>https://astro.build/episodes/index.html</loc></url></urlset>\n`
);
});
});