diff options
author | 2024-03-26 22:11:44 +0800 | |
---|---|---|
committer | 2024-03-26 10:11:44 -0400 | |
commit | 5f7e9c47e01116f6ec74b33770f480404680956a (patch) | |
tree | 26f066cae4fd11dd48c846239214c4c75c4ff783 | |
parent | 51a4ea5f723688b4c4745b3e9643d370a48d972d (diff) | |
download | astro-5f7e9c47e01116f6ec74b33770f480404680956a.tar.gz astro-5f7e9c47e01116f6ec74b33770f480404680956a.tar.zst astro-5f7e9c47e01116f6ec74b33770f480404680956a.zip |
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
-rw-r--r-- | .changeset/fluffy-cups-invent.md | 5 | ||||
-rw-r--r-- | packages/integrations/sitemap/src/index.ts | 1 | ||||
-rw-r--r-- | packages/integrations/sitemap/test/base-path.test.js | 24 |
3 files changed, 24 insertions, 6 deletions
diff --git a/.changeset/fluffy-cups-invent.md b/.changeset/fluffy-cups-invent.md new file mode 100644 index 000000000..0ea588ef1 --- /dev/null +++ b/.changeset/fluffy-cups-invent.md @@ -0,0 +1,5 @@ +--- +"@astrojs/sitemap": patch +--- + +Fixes an issue where the base path is missing in `sitemap-index.xml`. diff --git a/packages/integrations/sitemap/src/index.ts b/packages/integrations/sitemap/src/index.ts index 9b1ea5ddb..b0548d8f1 100644 --- a/packages/integrations/sitemap/src/index.ts +++ b/packages/integrations/sitemap/src/index.ts @@ -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, diff --git a/packages/integrations/sitemap/test/base-path.test.js b/packages/integrations/sitemap/test/base-path.test.js index 0417e4e2b..df3cadcc4 100644 --- a/packages/integrations/sitemap/test/base-path.test.js +++ b/packages/integrations/sitemap/test/base-path.test.js @@ -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' + ); }); }); }); |