diff options
author | 2022-01-08 08:25:37 -0500 | |
---|---|---|
committer | 2022-01-08 08:25:37 -0500 | |
commit | f008a19c9d4ad046ef7b24262605e8107c34a9bc (patch) | |
tree | 453da3358840cb006a8357312910c4c69b8fa047 | |
parent | 0bbc015a67d7a241043d75885c3c39b5363f3874 (diff) | |
download | astro-f008a19c9d4ad046ef7b24262605e8107c34a9bc.tar.gz astro-f008a19c9d4ad046ef7b24262605e8107c34a9bc.tar.zst astro-f008a19c9d4ad046ef7b24262605e8107c34a9bc.zip |
Fix sitemap.xml page urls (#2335)
* For pages, use the expected pathname, not the file name
* changeset
Diffstat (limited to '')
-rw-r--r-- | .changeset/bright-suns-brake.md | 5 | ||||
-rw-r--r-- | packages/astro/src/core/ssr/sitemap.ts | 2 | ||||
-rw-r--r-- | packages/astro/src/vite-plugin-build-html/index.ts | 3 | ||||
-rw-r--r-- | packages/astro/test/astro-sitemap-rss.test.js | 2 |
4 files changed, 8 insertions, 4 deletions
diff --git a/.changeset/bright-suns-brake.md b/.changeset/bright-suns-brake.md new file mode 100644 index 000000000..13660de30 --- /dev/null +++ b/.changeset/bright-suns-brake.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Preserve pathnames for sitemap.xml diff --git a/packages/astro/src/core/ssr/sitemap.ts b/packages/astro/src/core/ssr/sitemap.ts index fd39098e7..e392dd368 100644 --- a/packages/astro/src/core/ssr/sitemap.ts +++ b/packages/astro/src/core/ssr/sitemap.ts @@ -6,7 +6,7 @@ export function generateSitemap(pages: string[]): string { // 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')); + const urls = [...pages].filter((url) => !/404\/?$/.test(url)); 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) { diff --git a/packages/astro/src/vite-plugin-build-html/index.ts b/packages/astro/src/vite-plugin-build-html/index.ts index acb2c87cf..22bad8073 100644 --- a/packages/astro/src/vite-plugin-build-html/index.ts +++ b/packages/astro/src/vite-plugin-build-html/index.ts @@ -80,8 +80,7 @@ export function rollupPluginAstroBuildHTML(options: PluginOptions): VitePlugin { } for (const pathname of pageData.paths) { - const pathrepl = astroConfig.buildOptions.pageUrlFormat === 'directory' ? '/index.html' : pathname === '/' ? 'index.html' : '.html'; - pageNames.push(pathname.replace(/\/?$/, pathrepl).replace(/^\//, '')); + pageNames.push(pathname.replace(/\/?$/, '/').replace(/^\//, '')); const id = ASTRO_PAGE_PREFIX + pathname; const html = await ssrRender(renderers, mod, { astroConfig, diff --git a/packages/astro/test/astro-sitemap-rss.test.js b/packages/astro/test/astro-sitemap-rss.test.js index f193ed77b..ca9f8d0db 100644 --- a/packages/astro/test/astro-sitemap-rss.test.js +++ b/packages/astro/test/astro-sitemap-rss.test.js @@ -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/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/</loc></url><url><loc>https://astro.build/episode/rap-snitch-knishes/</loc></url><url><loc>https://astro.build/episode/rhymes-like-dimes/</loc></url><url><loc>https://astro.build/episodes/</loc></url></urlset>\n` ); }); }); |