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

fix(v2): Fix double trailingSlash in sitemap.xml #4004

Merged
merged 1 commit into from
Jan 6, 2021

Conversation

ntbosscher
Copy link
Contributor

Fix issue where when trailingSlash option is enabled, routes that already end in a / are shown with double slash at the end.

Motivation

Some of my routes show in sitemap.xml without a trailing slash, so I use trailingSlash to make them all consistent. However, some of my paths (e.g. /docs/ created by getting_started.md) already have a trailing slash. Currently /docs/ will be rendered as /docs// in the sitemap which isn't correct. This fix prevents that trailing double slash when the trailingSlash option is enabled.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

  1. Update your docusaurus.config.js to enable sitemap's trailingSlash option
plugins: [
    [
      '@docusaurus/plugin-sitemap',
      {
        id: 'plugin-sitemap-default',
        trailingSlash: true,
      },
    ],
  ],
  1. Create a page in /docs with slug: /
  2. Generate the sitemap by creating an optimized production build
  3. Verify that the build/sitemap.xml entry generated for /docs/ doesn't have a trailing slash

Related PRs

N/A

When `trailingSlash` option is enabled, routes that already end in a `/` are shown with double slash at the end.
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jan 6, 2021
@github-actions
Copy link

github-actions bot commented Jan 6, 2021

Size Change: -2 B (0%)

Total Size: 26.7 kB

ℹ️ View Unchanged
Filename Size Change
website/build/blog/2017/12/14/introducing-docusaurus/index.html 20.7 kB -2 B (0%)
website/build/docs/introduction/index.html 180 B 0 B
website/build/index.html 5.82 kB 0 B

compressed-size-action

@netlify
Copy link

netlify bot commented Jan 6, 2021

✔️ Deploy preview for docusaurus-2 ready!
Built without sensitive environment variables

🔨 Explore the source changes: 5edfc43

🔍 Inspect the deploy logs: https://app.netlify.com/sites/docusaurus-2/deploys/5ff5b74ae6e17f0007e0edc7

😎 Browse the preview: https://deploy-preview-4004--docusaurus-2.netlify.app

@github-actions
Copy link

github-actions bot commented Jan 6, 2021

⚡️ Lighthouse report for the changes in this PR:

Category Score
🟠 Performance 87
🟢 Accessibility 99
🟢 Best practices 100
🟢 SEO 100
🟢 PWA 95

Lighthouse ran on https://deploy-preview-4004--docusaurus-2.netlify.app/classic/

@slorber slorber changed the title Fix double trailingSlash in sitemap.xml fix(v2): Fix double trailingSlash in sitemap.xml Jan 6, 2021
@slorber slorber added the pr: bug fix This PR fixes a bug in a past release. label Jan 6, 2021
@slorber
Copy link
Collaborator

slorber commented Jan 6, 2021

LGTM, thanks 👍

@slorber slorber merged commit 8a9dfcf into facebook:master Jan 6, 2021
@slorber
Copy link
Collaborator

slorber commented Jan 6, 2021

weird, this PR has a prettier formatting issue that was not catched by the CI

Will be fixed by #4005

Also replaced code by our addTrailingSlash util (it does not add duplicate trailing slashes)

@lex111 lex111 added this to the v2.0.0-alpha.71 milestone Mar 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Signed Facebook CLA pr: bug fix This PR fixes a bug in a past release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants