Skip to content

Add trailing slash to auto generated sitemap.xml for directories only #10044

Description

@John-fg

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I'm using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

Description

Bing.com shows a redirection message with HTTP 301 for every page because each link in sitemap.xml is missing a trailing slash. The redirection message shown by the Bing.com search site is WEBMoved Permanently. The document has moved here. It does not display the actual content.

I'd like to:

  • prevent 301 redirects and use direct links in the generated sitemap.xml
  • have docusaurus generate trailing slashes in the generated sitemap.xml for directories.

Also see #4134

Reproducible demo

No response

Steps to reproduce

adding trailingSlash: true, to docusaurus.conf.js.

Expected behavior

Trailing slashes should only be used for actual directories.

Actual behavior

When 'trailingSlash' is added to docusaurus.conf.js within const conf = {..} is being refused with error messages:

const config = {
  title: 'Mysite',
  tagline: 'tagline',
  favicon: 'img/favicon.ico',

  // Set the production url of your site here
  url: 'https://mysite.tld',
  // Set the /<baseUrl>/ pathname under which your site is served
  // For GitHub pages deployment, it is often '/<projectName>/'
  baseUrl: '/',
  trailingSlash: true,

This creates a sitemap.xml with trailing slashes, building then fails due to broken links to anchors:

Error: Unable to build website for locale xx.
    at tryToBuildLocale (/home/user/mytopic/node_modules/@docusaurus/core/lib/commands/build.js:55:19)
    at async mapAsyncSequential (/home/user/mytopic/node_modules/@docusaurus/utils/lib/jsUtils.js:44:24)
    at async Command.build (/home/user/mytopic/node_modules/@docusaurus/core/lib/commands/build.js:82:21) {
  [cause]: Error: Docusaurus found broken links!

  Please check the pages of your site in the list below, and make sure you don't reference any path that does not exist.
  Note: it's possible to ignore broken links with the 'onBrokenLinks' Docusaurus configuration, and let the build pass.

  Exhaustive list of all broken links found:
  - Broken link on source page path = /docs/sub1/:
     -> linking to ./mydoc/#table-1 (resolved as: /docs/sub1/mydoc/#table-1)
     -> linking to mydoc2/#table-2 (resolved as: /docs/sub1/mydoc2/#table-2)
 (removed a list of more broken links)

It looks like links to anchors are not created properly. The directories here are mydoc and mydoc2, the anchors referenced on the index pages are #table-1 and #table-2.

The link in the md file looks like this:

[table 1](./mydoc#table-1) 
[table 2](mydoc2#table-2)

Your environment

  • Public source code: Docusaurus
  • Public site URL: n/a
  • Docusaurus version used: 3.2.1
  • Environment name and version (e.g. Chrome 89, Node.js 16.4): node v18.19.0
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS): Debian 12 (bookworm).

Self-service

  • I'd be willing to fix this bug myself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn error in the Docusaurus core causing instability or issues with its executionclosed: can't reproThis bug is because of some local setup that can't be reproduced.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions