Skip to content

Commit 2d1a880

Browse files
authored
fix(gatsby-plugin-sitemap): fix pathPrefix handling (#34158)
1 parent 41af327 commit 2d1a880

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

packages/gatsby-plugin-sitemap/src/__tests__/gatsby-node.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,21 @@ describe(`gatsby-plugin-sitemap Node API`, () => {
141141
const options = {
142142
entryLimit: 1,
143143
}
144+
const assetPrefix = `https://cdn.example.com`
144145
const prefix = `/test`
145146
await onPostBuild(
146-
{ graphql, pathPrefix: prefix, reporter },
147+
{
148+
graphql,
149+
basePath: prefix,
150+
pathPrefix: `${assetPrefix}${prefix}`,
151+
reporter,
152+
},
147153
await schema.validateAsync(options)
148154
)
149155
const { sourceData } = sitemap.simpleSitemapAndIndex.mock.calls[0][0]
150156
sourceData.forEach(page => {
151157
expect(page.url).toEqual(expect.stringContaining(prefix))
158+
expect(page.url).not.toEqual(expect.stringContaining(assetPrefix))
152159
})
153160
})
154161

packages/gatsby-plugin-sitemap/src/gatsby-node.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { prefixPath, pageFilter, REPORTER_PREFIX } from "./internals"
66
exports.pluginOptionsSchema = pluginOptionsSchema
77

88
exports.onPostBuild = async (
9-
{ graphql, reporter, pathPrefix },
9+
{ graphql, reporter, basePath, pathPrefix },
1010
{
1111
output,
1212
entryLimit,
@@ -70,7 +70,7 @@ exports.onPostBuild = async (
7070
serialize(page, { resolvePagePath })
7171
)
7272
serializedPages.push({
73-
url: prefixPath({ url, siteUrl, pathPrefix }),
73+
url: prefixPath({ url, siteUrl, pathPrefix: basePath }),
7474
...rest,
7575
})
7676
} catch (err) {

0 commit comments

Comments
 (0)