-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allows sitemap output on root of public folder #31130
Allows sitemap output on root of public folder #31130
Conversation
FYI, I've tested this locally and works fine with an empty string but will fail with |
Curious why an empty string vs |
@KyleAMathews I tested with "/" and noticed that the header that was created had double slashes in it (so it showed "//sitemap-index.xml"), using a blank string fixed that! |
Ah ok, that's the bug that should be fixed then here —
When joining paths, it's best to use ➜ gatsby-plugin-sitemap git: ✗ node
Welcome to Node.js v16.0.0.
Type ".help" for more information.
> const path = require(`path`)
undefined
> path.join(`/`, `/`)
'/' |
I do wonder if this issue is showing in other bits, given this: gatsby/packages/gatsby-plugin-sitemap/src/gatsby-ssr.js Lines 5 to 6 in a2a9dc9
|
I was going to summit the pr to convert to |
This looks more like it!
But I do wonder if there's already some dependency that Gatsby is using to do this correctly? |
Good call, stark overflow looks like it has some good suggestions. https://stackoverflow.com/questions/16301503/can-i-use-requirepath-join-to-safely-concatenate-urls |
ff1a167
to
c866063
Compare
Given the comments from @KyleAMathews, I've changed the code to fix when I've also added a small test to ensure this keeps the expected behavior. |
Thanks for the fix and especially for the tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't run the code but looks good.
Ah yeah, Nice work @pedrolamas ! |
Published in |
Description
All this PR does is allow developers to set the
output
option on thegatsby-sitemap-plugin
to""
(empty string) so that the files can be written to the root of the public folder.Some (like me) might prefer that instead of creating a subfolder to store the files, plus this mitigates a separate issue where the index file always points to the root folder instead of the specified output folder.
Documentation
https://www.gatsbyjs.com/plugins/gatsby-plugin-sitemap/
Related Issues
Fixes #31095