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 = ``; 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( - `https://astro.build/episode/fazers/index.htmlhttps://astro.build/episode/rap-snitch-knishes/index.htmlhttps://astro.build/episode/rhymes-like-dimes/index.htmlhttps://astro.build/episodes/index.html\n` + `https://astro.build/episode/fazers/https://astro.build/episode/rap-snitch-knishes/https://astro.build/episode/rhymes-like-dimes/https://astro.build/episodes/\n` ); }); });