mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
* 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:
parent
ddac977748
commit
cc1dae55c8
3 changed files with 9 additions and 2 deletions
5
.changeset/angry-pillows-accept.md
Normal file
5
.changeset/angry-pillows-accept.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Exclude 404 pages from sitemap generation
|
|
@ -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) {
|
||||
|
|
|
@ -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`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue