0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

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>
This commit is contained in:
Nate Moore 2021-12-06 16:50:30 -06:00 committed by GitHub
parent ddac977748
commit cc1dae55c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Exclude 404 pages from sitemap generation

View file

@ -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) {

View file

@ -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`
);
});
});