Skip to content

Commit

Permalink
fix: correctly prefix sitemaps with pathPrefix
Browse files Browse the repository at this point in the history
  • Loading branch information
moonmeister committed May 2, 2021
1 parent 504420f commit 84ef4b5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
38 changes: 38 additions & 0 deletions packages/gatsby-plugin-sitemap/src/__tests__/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,42 @@ describe(`gatsby-plugin-sitemap Node API`, () => {
expect(page.url).toEqual(expect.stringContaining(prefix))
})
})

it(`should output modified paths to sitemap`, async () => {
const graphql = jest.fn()
graphql.mockResolvedValue({
data: {
site: {
siteMetadata: {
siteUrl: `http://dummy.url`,
},
},
allSitePage: {
nodes: [
{
path: `/page-1`,
},
{
path: `/page-2`,
},
],
},
},
})
const prefix = `/test`
const subdir = `/subdir`
const options = {
output: subdir,
}
await onPostBuild(
{ graphql, pathPrefix: prefix, reporter },
await schema.validateAsync(options)
)
expect(sitemap.simpleSitemapAndIndex.mock.calls[0][0].publicBasePath).toBe(
path.posix.join(prefix, subdir)
)
expect(sitemap.simpleSitemapAndIndex.mock.calls[0][0].destinationDir).toBe(
path.join(`public`, subdir)
)
})
})
3 changes: 2 additions & 1 deletion packages/gatsby-plugin-sitemap/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ exports.onPostBuild = async (
}

const sitemapWritePath = path.join(`public`, output)
const sitemapPublicPath = path.posix.join(pathPrefix, output)

return simpleSitemapAndIndex({
hostname: siteUrl,
publicBasePath: output,
publicBasePath: sitemapPublicPath,
destinationDir: sitemapWritePath,
sourceData: serializedPages,
limit: entryLimit,
Expand Down

0 comments on commit 84ef4b5

Please sign in to comment.