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:
parent
d96d6d453d
commit
7f6c35f636
2 changed files with 12 additions and 2 deletions
|
@ -1,5 +1,4 @@
|
||||||
import type { BuildOutput } from '../@types/astro';
|
import type { BuildOutput } from '../@types/astro';
|
||||||
|
|
||||||
import { canonicalURL } from './util.js';
|
import { canonicalURL } from './util.js';
|
||||||
|
|
||||||
/** Construct sitemap.xml given a set of URLs */
|
/** 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>();
|
const uniqueURLs = new Set<string>();
|
||||||
|
|
||||||
// TODO: find way to respect <link rel="canonical"> URLs here
|
// 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
|
// look through built pages, only add HTML
|
||||||
for (const id of Object.keys(buildState)) {
|
for (const id of Object.keys(buildState)) {
|
||||||
if (buildState[id].contentType !== 'text/html') continue;
|
if (buildState[id].contentType !== 'text/html') continue;
|
||||||
|
if (id === '/404.html') continue;
|
||||||
uniqueURLs.add(canonicalURL(id, site).href);
|
uniqueURLs.add(canonicalURL(id, site).href);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
packages/astro/test/fixtures/astro-rss/src/pages/404.astro
vendored
Normal file
10
packages/astro/test/fixtures/astro-rss/src/pages/404.astro
vendored
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
---
|
||||||
|
---
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>404</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
404
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in a new issue