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

When multiple i18n are configured, the plug-in will report an error when using the Link tag. #9957

Closed
6 of 7 tasks
CodFrm opened this issue Mar 16, 2024 · 1 comment
Closed
6 of 7 tasks
Labels
bug An error in the Docusaurus core causing instability or issues with its execution closed: wontfix A fix will bring significant overhead, or is out of scope (for feature requests) status: needs triage This issue has not been triaged by maintainers

Comments

@CodFrm
Copy link

CodFrm commented Mar 16, 2024

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

Using the Link tag in the plug-in will report the following error:

Error: Unable to build website for locale zh-CN.
    at tryToBuildLocale (/Users/codfrm/Code/my-website/node_modules/@docusaurus/core/lib/commands/build.js:55:19)
    at async mapAsyncSequential (/Users/codfrm/Code/my-website/node_modules/@docusaurus/utils/lib/jsUtils.js:44:24)
    at async Command.build (/Users/codfrm/Code/my-website/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 = /test:
     -> linking to /zh-CN/test/2
  - Broken link on source page path = /test/2:
     -> linking to /zh-CN/test/2
  
      at throwError (/Users/codfrm/Code/my-website/node_modules/@docusaurus/logger/lib/index.js:79:11)
      at reportBrokenLinks (/Users/codfrm/Code/my-website/node_modules/@docusaurus/core/lib/server/brokenLinks.js:242:47)
      at handleBrokenLinks (/Users/codfrm/Code/my-website/node_modules/@docusaurus/core/lib/server/brokenLinks.js:274:5)
      at buildLocale (/Users/codfrm/Code/my-website/node_modules/@docusaurus/core/lib/commands/build.js:192:47)
      at async tryToBuildLocale (/Users/codfrm/Code/my-website/node_modules/@docusaurus/core/lib/commands/build.js:46:20)
      at async mapAsyncSequential (/Users/codfrm/Code/my-website/node_modules/@docusaurus/utils/lib/jsUtils.js:44:24)
      at async Command.build (/Users/codfrm/Code/my-website/node_modules/@docusaurus/core/lib/commands/build.js:82:21)
}

[INFO] Docusaurus version: 3.1.1
Node version: v20.11.1

Reproducible demo

No response

Steps to reproduce

Below is a reproducible sample:

test.zip

Expected behavior

No error is reported and the alternate in build/zh-CN/test/index.html is generated correctly.

Actual behavior

An error is reported and the alternate in build/zh-CN/test/index.html generates multiple slashes

    <link
      data-rh="true"
      rel="alternate"
      href="https://your-docusaurus-site.example.com/zh-CN//test"
      hreflang="zh-CN"
    />

Your environment

  • Public source code:
  • Public site URL:
  • Docusaurus version used: 3.1.1
  • Environment name and version (e.g. Chrome 89, Node.js 16.4): Edge 122.0.2365.80,Nodejs v20.11.1
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS): MacOS 14.0 (23A344)

Self-service

  • I'd be willing to fix this bug myself.
@CodFrm CodFrm added bug An error in the Docusaurus core causing instability or issues with its execution status: needs triage This issue has not been triaged by maintainers labels Mar 16, 2024
@slorber
Copy link
Collaborator

slorber commented Mar 20, 2024

The reported errors are correct, and you can see the problem if you run your site with yarn start --locale zh-CN

This is because the localized variant of your site is using baseUrl: '/zh-CN/' automatically.

Currently, it is the responsibility of plugin authors to add the site baseUrl to the route config. If you do this, it will work:

    async contentLoaded({ content, actions }): Promise<void> {
      const { addRoute } = actions;
      addRoute({
        path: context.baseUrl+"test",
        component: "@theme/Test",
      });

      addRoute({
        path: context.baseUrl+"/test/2",
        component: "@theme/Test",
      });
    },

I'll look into simplifying this later, and try to make your code work, but for now this is the current state of how things work, and changing this behavior would be a breaking change.

@slorber slorber closed this as not planned Won't fix, can't repro, duplicate, stale Mar 20, 2024
@slorber slorber added closed: wontfix A fix will bring significant overhead, or is out of scope (for feature requests) status: needs triage This issue has not been triaged by maintainers and removed status: needs triage This issue has not been triaged by maintainers labels Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An error in the Docusaurus core causing instability or issues with its execution closed: wontfix A fix will bring significant overhead, or is out of scope (for feature requests) status: needs triage This issue has not been triaged by maintainers
Projects
None yet
Development

No branches or pull requests

2 participants