Skip to content

Commit

Permalink
fix(gatsby-plugin-sitemap): fix pathPrefix handling (#34158)
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet authored Dec 2, 2021
1 parent 41af327 commit 2d1a880
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion packages/gatsby-plugin-sitemap/src/__tests__/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,21 @@ describe(`gatsby-plugin-sitemap Node API`, () => {
const options = {
entryLimit: 1,
}
const assetPrefix = `https://cdn.example.com`
const prefix = `/test`
await onPostBuild(
{ graphql, pathPrefix: prefix, reporter },
{
graphql,
basePath: prefix,
pathPrefix: `${assetPrefix}${prefix}`,
reporter,
},
await schema.validateAsync(options)
)
const { sourceData } = sitemap.simpleSitemapAndIndex.mock.calls[0][0]
sourceData.forEach(page => {
expect(page.url).toEqual(expect.stringContaining(prefix))
expect(page.url).not.toEqual(expect.stringContaining(assetPrefix))
})
})

Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby-plugin-sitemap/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { prefixPath, pageFilter, REPORTER_PREFIX } from "./internals"
exports.pluginOptionsSchema = pluginOptionsSchema

exports.onPostBuild = async (
{ graphql, reporter, pathPrefix },
{ graphql, reporter, basePath, pathPrefix },
{
output,
entryLimit,
Expand Down Expand Up @@ -70,7 +70,7 @@ exports.onPostBuild = async (
serialize(page, { resolvePagePath })
)
serializedPages.push({
url: prefixPath({ url, siteUrl, pathPrefix }),
url: prefixPath({ url, siteUrl, pathPrefix: basePath }),
...rest,
})
} catch (err) {
Expand Down

0 comments on commit 2d1a880

Please sign in to comment.