0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-01-06 22:10:10 -05:00

fix(sitemap): fix missing base path in sitemap-index.xml (#10557)

* fix(sitemap): fix missing base path in `sitemap-index.xml`

* test(sitemap): update test cases in `base-path.test.js`

* chore: add changeset
This commit is contained in:
Ming-jun Lu 2024-03-26 22:11:44 +08:00 committed by GitHub
parent 51a4ea5f72
commit 5f7e9c47e0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 6 deletions

View file

@ -0,0 +1,5 @@
---
"@astrojs/sitemap": patch
---
Fixes an issue where the base path is missing in `sitemap-index.xml`.

View file

@ -170,6 +170,7 @@ const createPlugin = (options?: SitemapOptions): AstroIntegration => {
await simpleSitemapAndIndex({
hostname: finalSiteUrl.href,
destinationDir: destDir,
publicBasePath: config.base,
sourceData: urlData,
limit: entryLimit,
gzip: false,

View file

@ -16,9 +16,15 @@ describe('URLs with base path', () => {
});
it('Base path is concatenated correctly', async () => {
const data = await readXML(fixture.readFile('/client/sitemap-0.xml'));
const urls = data.urlset.url;
assert.equal(urls[0].loc[0], 'http://example.com/base/one/');
const [sitemapZero, sitemapIndex] = await Promise.all([
readXML(fixture.readFile('/client/sitemap-0.xml')),
readXML(fixture.readFile('/client/sitemap-index.xml')),
]);
assert.equal(sitemapZero.urlset.url[0].loc[0], 'http://example.com/base/one/');
assert.equal(
sitemapIndex.sitemapindex.sitemap[0].loc[0],
'http://example.com/base/sitemap-0.xml'
);
});
});
@ -32,9 +38,15 @@ describe('URLs with base path', () => {
});
it('Base path is concatenated correctly', async () => {
const data = await readXML(fixture.readFile('/sitemap-0.xml'));
const urls = data.urlset.url;
assert.equal(urls[0].loc[0], 'http://example.com/base/123/');
const [sitemapZero, sitemapIndex] = await Promise.all([
readXML(fixture.readFile('/sitemap-0.xml')),
readXML(fixture.readFile('/sitemap-index.xml')),
]);
assert.equal(sitemapZero.urlset.url[0].loc[0], 'http://example.com/base/123/');
assert.equal(
sitemapIndex.sitemapindex.sitemap[0].loc[0],
'http://example.com/base/sitemap-0.xml'
);
});
});
});