Skip to content

Commit d95b258

Browse files
moonmeistergatsbybot
and
gatsbybot
authored
fix(gatsby-plugin-sitemap): Sitemap path bug (#31184)
Co-authored-by: gatsbybot <[email protected]>
1 parent 1a32958 commit d95b258

File tree

4 files changed

+63
-15
lines changed

4 files changed

+63
-15
lines changed

packages/gatsby-plugin-sitemap/package.json

+5-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22
"name": "gatsby-plugin-sitemap",
33
"description": "Gatsby plugin that automatically creates a sitemap for your site",
44
"version": "4.2.0-next.1",
5-
"author": "Nicholas Young &lt;[email protected]&gt;",
5+
"contributors": [
6+
"Alex Moon <[email protected]>",
7+
"Nicholas Young <[email protected]>"
8+
],
69
"bugs": {
710
"url": "https://github.com/gatsbyjs/gatsby/issues"
811
},
912
"dependencies": {
1013
"@babel/runtime": "^7.12.5",
1114
"common-tags": "^1.8.0",
1215
"minimatch": "^3.0.4",
13-
"sitemap": "^6.3.0"
16+
"sitemap": "^7.0.0"
1417
},
1518
"devDependencies": {
1619
"@babel/cli": "^7.12.1",

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

+38
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,42 @@ describe(`gatsby-plugin-sitemap Node API`, () => {
155155
expect(page.url).toEqual(expect.stringContaining(prefix))
156156
})
157157
})
158+
159+
it(`should output modified paths to sitemap`, async () => {
160+
const graphql = jest.fn()
161+
graphql.mockResolvedValue({
162+
data: {
163+
site: {
164+
siteMetadata: {
165+
siteUrl: `http://dummy.url`,
166+
},
167+
},
168+
allSitePage: {
169+
nodes: [
170+
{
171+
path: `/page-1`,
172+
},
173+
{
174+
path: `/page-2`,
175+
},
176+
],
177+
},
178+
},
179+
})
180+
const prefix = `/test`
181+
const subdir = `/subdir`
182+
const options = {
183+
output: subdir,
184+
}
185+
await onPostBuild(
186+
{ graphql, pathPrefix: prefix, reporter },
187+
await schema.validateAsync(options)
188+
)
189+
expect(sitemap.simpleSitemapAndIndex.mock.calls[0][0].publicBasePath).toBe(
190+
path.posix.join(prefix, subdir)
191+
)
192+
expect(sitemap.simpleSitemapAndIndex.mock.calls[0][0].destinationDir).toBe(
193+
path.join(`public`, subdir)
194+
)
195+
})
158196
})

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,13 @@ exports.onPostBuild = async (
8383
}
8484
}
8585

86-
const sitemapPath = path.join(`public`, output)
86+
const sitemapWritePath = path.join(`public`, output)
87+
const sitemapPublicPath = path.posix.join(pathPrefix, output)
8788

8889
return simpleSitemapAndIndex({
8990
hostname: siteUrl,
90-
destinationDir: sitemapPath,
91+
publicBasePath: sitemapPublicPath,
92+
destinationDir: sitemapWritePath,
9193
sourceData: serializedPages,
9294
limit: entryLimit,
9395
gzip: false,

yarn.lock

+16-11
Original file line numberDiff line numberDiff line change
@@ -4631,7 +4631,7 @@
46314631
"@types/node" "*"
46324632
form-data "^3.0.0"
46334633

4634-
"@types/node@*", "@types/node@>= 8", "@types/node@^14.10.2", "@types/node@^14.14.10", "@types/node@^14.14.5", "@types/node@^14.6.4":
4634+
"@types/node@*", "@types/node@>= 8", "@types/node@^14.10.2", "@types/node@^14.14.10", "@types/node@^14.14.5":
46354635
version "14.14.31"
46364636
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.31.tgz#72286bd33d137aa0d152d47ec7c1762563d34055"
46374637
integrity sha512-vFHy/ezP5qI0rFgJ7aQnjDXwAMrG0KqqIH7tQG5PPv3BWBayOPIQNBjVc/P6hhdZfMx51REc6tfDNXHUio893g==
@@ -4641,6 +4641,11 @@
46414641
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.6.tgz#7b73cce37352936e628c5ba40326193443cfba25"
46424642
integrity sha512-sRVq8d+ApGslmkE9e3i+D3gFGk7aZHAT+G4cIpIEdLJYPsWiSPwcAnJEjddLQQDqV3Ra2jOclX/Sv6YrvGYiWA==
46434643

4644+
"@types/node@^15.0.1":
4645+
version "15.0.1"
4646+
resolved "https://registry.yarnpkg.com/@types/node/-/node-15.0.1.tgz#ef34dea0881028d11398be5bf4e856743e3dc35a"
4647+
integrity sha512-TMkXt0Ck1y0KKsGr9gJtWGjttxlZnnvDtphxUOSd0bfaR6Q1jle+sPvrzNR1urqYTWMinoKvjKfXUGsumaO1PA==
4648+
46444649
"@types/node@^8.5.7":
46454650
version "8.10.59"
46464651
resolved "https://registry.yarnpkg.com/@types/node/-/node-8.10.59.tgz#9e34261f30183f9777017a13d185dfac6b899e04"
@@ -5965,10 +5970,10 @@ are-we-there-yet@~1.1.2:
59655970
delegates "^1.0.0"
59665971
readable-stream "^2.0.6"
59675972

5968-
arg@^4.1.3:
5969-
version "4.1.3"
5970-
resolved "https://registry.yarnpkg.com/arg/-/arg-4.1.3.tgz#269fc7ad5b8e42cb63c896d5666017261c144089"
5971-
integrity sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==
5973+
arg@^5.0.0:
5974+
version "5.0.0"
5975+
resolved "https://registry.yarnpkg.com/arg/-/arg-5.0.0.tgz#a20e2bb5710e82950a516b3f933fee5ed478be90"
5976+
integrity sha512-4P8Zm2H+BRS+c/xX1LrHw0qKpEhdlZjLCgWy+d78T9vqa2Z2SiD2wMrYuWIAFy5IZUD7nnNXroRttz+0RzlrzQ==
59725977

59735978
argparse@^1.0.10, argparse@^1.0.6, argparse@^1.0.7:
59745979
version "1.0.10"
@@ -24910,14 +24915,14 @@ sisteransi@^1.0.5:
2491024915
resolved "https://registry.yarnpkg.com/sisteransi/-/sisteransi-1.0.5.tgz#134d681297756437cc05ca01370d3a7a571075ed"
2491124916
integrity sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==
2491224917

24913-
sitemap@^6.3.0:
24914-
version "6.3.0"
24915-
resolved "https://registry.yarnpkg.com/sitemap/-/sitemap-6.3.0.tgz#c9affa49d654b5bd76a56a8e67cee3c17560a8f3"
24916-
integrity sha512-U0jS5b+V/MQOkmkqwq3ow++sE1A+F4Yo/nDU5wksiGFO7ww7VutOXJWdM2wk54Ztvl4UmlX65l2GVz5jeI4rgw==
24918+
sitemap@^7.0.0:
24919+
version "7.0.0"
24920+
resolved "https://registry.yarnpkg.com/sitemap/-/sitemap-7.0.0.tgz#022bef4df8cba42e38e1fe77039f234cab0372b6"
24921+
integrity sha512-Ud0jrRQO2k7fEtPAM+cQkBKoMvxQyPKNXKDLn8tRVHxRCsdDQ2JZvw+aZ5IRYYQVAV9iGxEar6boTwZzev+x3g==
2491724922
dependencies:
24918-
"@types/node" "^14.6.4"
24923+
"@types/node" "^15.0.1"
2491924924
"@types/sax" "^1.2.1"
24920-
arg "^4.1.3"
24925+
arg "^5.0.0"
2492124926
sax "^1.2.4"
2492224927

2492324928
slash@^1.0.0:

0 commit comments

Comments
 (0)