Skip to content

Commit

Permalink
fix(sitemap): fix missing base path in sitemap-index.xml (#10557)
Browse files Browse the repository at this point in the history
* fix(sitemap): fix missing base path in `sitemap-index.xml`

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

* chore: add changeset
  • Loading branch information
mingjunlu authored Mar 26, 2024
1 parent 51a4ea5 commit 5f7e9c4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/fluffy-cups-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/sitemap": patch
---

Fixes an issue where the base path is missing in `sitemap-index.xml`.
1 change: 1 addition & 0 deletions packages/integrations/sitemap/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 18 additions & 6 deletions packages/integrations/sitemap/test/base-path.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
});
});

Expand All @@ -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'
);
});
});
});

0 comments on commit 5f7e9c4

Please sign in to comment.