Skip to content

Commit

Permalink
fix(#7472): sitemap should only exclude 404 and 500 pages
Browse files Browse the repository at this point in the history
  • Loading branch information
natemoo-re committed Jul 14, 2023
1 parent 795d598 commit 4a518ae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/chatty-pigs-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/sitemap': minor
---

Ensure sitemap only excludes numerical pages matching `/404` and `/500` exactly
4 changes: 2 additions & 2 deletions packages/integrations/sitemap/src/generate-sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import type { EnumChangefreq } from 'sitemap';
import type { SitemapItem, SitemapOptions } from './index.js';
import { parseUrl } from './utils/parse-url.js';

const STATUS_CODE_PAGE_REGEXP = /\/[0-9]{3}\/?$/;
const STATUS_CODE_PAGES = new Set(['/404', '/500']);

/** Construct sitemap.xml given a set of URLs */
export function generateSitemap(pages: string[], finalSiteUrl: string, opts: SitemapOptions) {
const { changefreq, priority, lastmod: lastmodSrc, i18n } = opts!;
// TODO: find way to respect <link rel="canonical"> URLs here
const urls = [...pages].filter((url) => !STATUS_CODE_PAGE_REGEXP.test(url));
const urls = [...pages].filter((url) => !STATUS_CODE_PAGES.has(url.endsWith('/') ? url.slice(0, -1) : url));
urls.sort((a, b) => a.localeCompare(b, 'en', { numeric: true })); // sort alphabetically so sitemap is same each time

const lastmod = lastmodSrc?.toISOString();
Expand Down

0 comments on commit 4a518ae

Please sign in to comment.