skip 404.html pages in sitemap generation (#1287)

* skip 404.html pages in sitemap generation

* update path check for 404
This commit is contained in:
Mani Gandham 2021-09-01 15:02:11 -07:00 committed by GitHub
parent d96d6d453d
commit 7f6c35f636
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View file

@ -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<string>();
// TODO: find way to respect <link rel="canonical"> 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);
}

View file

@ -0,0 +1,10 @@
---
---
<html>
<head>
<title>404</title>
</head>
<body>
404
</body>
</html>