Skip to content
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

[gatsby-plugin-sitemap]: Sub path is stripped from siteUrl in sitemap-index.xml #32080

Closed
prichey opened this issue Jun 23, 2021 · 9 comments
Closed
Labels
stale? Issue that may be closed soon due to the original author not responding any more. status: awaiting author response Additional information has been requested from the author topic: plugins Related to plugin system, themes & catch-all for plugins that don't have a label type: bug An issue or pull request relating to a bug in Gatsby

Comments

@prichey
Copy link
Contributor

prichey commented Jun 23, 2021

Description

My siteUrl is mangled in the sitemap.xml. In this example, the siteUrl is https://mysite.com/foo but the location in sitemap-index.xml is https://mysite.com/sitemap/sitemap-0.xml (rather than https://mysite.com/foo/sitemap/sitemap-0.xml).

gatsby-config.js:

module.exports = {
  /* Your site config here */
  siteMetadata: {
    siteUrl: 'https://mysite.com/foo'
  },
  plugins: ['gatsby-plugin-sitemap'],
}

Steps to reproduce

npm run build

Expected result

public/sitemap/sitemap-index.xml:

<?xml version="1.0" encoding="UTF-8"?><sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><sitemap><loc>https://mysite.com/foo/sitemap/sitemap-0.xml</loc></sitemap></sitemapindex>

Actual result

public/sitemap/sitemap-index.xml:

<?xml version="1.0" encoding="UTF-8"?><sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><sitemap><loc>https://mysite.com/sitemap/sitemap-0.xml</loc></sitemap></sitemapindex>

Environment

  System:
    OS: macOS 11.4
    CPU: (4) x64 Intel(R) Core(TM) i5-7267U CPU @ 3.10GHz
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.15.4 - /var/folders/gb/n4714k6158z5svmlr6y_yrfh0000gn/T/fnm_multishell_59135_1624470024651/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.10 - /var/folders/gb/n4714k6158z5svmlr6y_yrfh0000gn/T/fnm_multishell_59135_1624470024651/bin/npm
  Languages:
    Python: 2.7.17 - /usr/local/bin/python
  Browsers:
    Chrome: 91.0.4472.114
    Firefox: 88.0.1
    Safari: 14.1.1
  npmPackages:
    gatsby: ^3.6.2 => 3.6.2 
    gatsby-plugin-sitemap: ^4.4.0 => 4.4.0 
  npmGlobalPackages:
    gatsby: 3.5.1

Reproduction repo: https://github.com/prichey/sitemap-bug

@prichey prichey added the type: bug An issue or pull request relating to a bug in Gatsby label Jun 23, 2021
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jun 23, 2021
@moonmeister
Copy link
Contributor

So my guess is this is happening because the siteUrl is expected to be a domain. https://mysite.com/. If you're hosting a Gatsby site at a sub path you need to use the built in path prefix functionality. https://www.gatsbyjs.com/docs/how-to/previews-deploys-hosting/path-prefix/

@moonmeister
Copy link
Contributor

moonmeister commented Jun 23, 2021

I could be wrong here but that's always been my assumption. Given I wrote the sitemap plugin this is probably why that's getting stripped, cause I expected it to be a domain.

It's been a while but I believe if you are using the pathPrefix functionality the sitemap plugin will correctly append that in the sitemap. If not we can fix that.

@prichey
Copy link
Contributor Author

prichey commented Jun 24, 2021

Thing is, that doesn't work either:

gatsby-config.js:

module.exports = {
  pathPrefix: "/foo",
  siteMetadata: {
    siteUrl: "https://mysite.com",
  },
  plugins: ["gatsby-plugin-sitemap"],
}

-> sitemap-index.xml:

<?xml version="1.0" encoding="UTF-8"?><sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><sitemap><loc>https://mysite.com/sitemap/sitemap-0.xml</loc></sitemap></sitemapindex>

The path in the output is still https://mysite.com/sitemap/sitemap-0.xml rather than https://mysite.com/foo/sitemap/sitemap-0.xml

@prichey
Copy link
Contributor Author

prichey commented Jun 24, 2021

Reproduction branch here: https://github.com/prichey/sitemap-bug/tree/path-prefix. Thanks for the quick response!

@moonmeister
Copy link
Contributor

Good to know!! Looks like this was missed.

I'll fix this if I have time but I work on Gatsby for fun so I don't have a timeline. Anyone who wants to tackle this please do so.

@moonmeister moonmeister added help wanted Issue with a clear description that the community can help with. status: confirmed Issue with steps to reproduce the bug that’s been verified by at least one reviewer. topic: plugins Related to plugin system, themes & catch-all for plugins that don't have a label and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Jun 24, 2021
@gatsbyjs gatsbyjs deleted a comment from BastavChoudhury Jun 27, 2021
@antdking
Copy link

It's possible this will fix your issue, as it changes to using config.pathPrefix: #32107

@moonmeister
Copy link
Contributor

moonmeister commented Jun 29, 2021

Okay, I checked out your repro and this is working as expected. you need to use Gatsby's path prefix functionality. If you gatsby config is:

module.exports = {
  /* Your site config here */
  pathPrefix: '/foo',
  siteMetadata: {
    siteUrl: 'https://mysite.com/',
  },
  plugins: ['gatsby-plugin-sitemap'],
}

then you use the command gatsby build --prefix-paths for the build and everything is done correctly.

#32107 will make sure that the asset prefix isn't also appended and will fix a different bug.

@moonmeister moonmeister added status: awaiting reviewer response A pull request that is currently awaiting a reviewer's response status: awaiting author response Additional information has been requested from the author and removed help wanted Issue with a clear description that the community can help with. status: confirmed Issue with steps to reproduce the bug that’s been verified by at least one reviewer. status: awaiting reviewer response A pull request that is currently awaiting a reviewer's response labels Jun 29, 2021
@github-actions
Copy link

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here.
If we missed this issue or if you want to keep it open, please reply here.
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

@github-actions github-actions bot added the stale? Issue that may be closed soon due to the original author not responding any more. label Jul 20, 2021
@github-actions
Copy link

Hey again!

It’s been 60 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it.
Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to comment on this issue or create a new one if you need anything else.
As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks again for being part of the Gatsby community! 💪💜

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale? Issue that may be closed soon due to the original author not responding any more. status: awaiting author response Additional information has been requested from the author topic: plugins Related to plugin system, themes & catch-all for plugins that don't have a label type: bug An issue or pull request relating to a bug in Gatsby
Projects
None yet
Development

No branches or pull requests

3 participants