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

SEO: hreflang alternate link wrongful destination if baseURL contains defaultlocale. #6462

Open
6 of 7 tasks
TomPeirs opened this issue Jan 24, 2022 · 1 comment · May be fixed by #6731
Open
6 of 7 tasks

SEO: hreflang alternate link wrongful destination if baseURL contains defaultlocale. #6462

TomPeirs opened this issue Jan 24, 2022 · 1 comment · May be fixed by #6731
Labels
bug An error in the Docusaurus core causing instability or issues with its execution domain: i18n Related to the i18n system

Comments

@TomPeirs
Copy link

TomPeirs commented Jan 24, 2022

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

The hreflang attribute in the head of a document is pointing to the wrong i18n paths.
https://docusaurus.io/docs/seo#global-metadata

Take the following URL:
TestURL: https://docs.boc-group.com/adoit/en/docs/14.0/user_manual/

If you inspect the DOM you will find the following:
<link data-react-helmet="true" rel="alternate" href="https://docs.boc-group.com/adoit/en/de/docs/14.0/user_manual/" hreflang="de">
AND
<link data-react-helmet="true" rel="alternate" href="https://docs.boc-group.com/adoit/docs/14.0/user_manual/" hreflang="de">
In the first alternate URL the i18n locale is added behind the baseURL.
In the second alternate URL the default locale is removed from the baseURL
Meaning that both links will not work

The alternate URL is pointing to /i18n-veriable/path.. and therefore this URL points to /en/de/ instead of /de/ because my baseurl already has the defaultlocale /en/ part of the baseurl. (I have 2 deployments, one for each locale.)
-> This leads to algolia trying to crawl a ton of wrongfull records.

Steps to reproduce

  1. Configure Base URL to include locale.
  2. In package.json build the application in a non traditional way by building to a dedicated output.
    Meaning that in the output directory on the root level there is no output, only in subfolder /en and /de (for each locale):
    "build_i18n": "cross-env LOCALE='en' BASE_URL='/adoit/en/' docusaurus build --locale en --out-dir build/en && cross-env LOCALE='de' BASE_URL='/adoit/de/' docusaurus build --locale de --out-dir build/de",
  3. Example docusaurus.config.js: baseUrl: process.env.BASE_URL,

With this setup you basically build your project for each language to a dedicated output, and via a deployment instance of your choice you can deploy to your liking.

However , with the traditional i18n config like below docusaurus will automtically add the hreflang attribute by appending the i18n variable to the baseURL. But docusaurus does not consider your deployment.

    i18n: {
        defaultLocale: 'en',
        locales: ['en', 'de'],
    },

** !! Docusaurus makes the assumption by default that your default locale is NOT part of your URL.**

A very similar issue arrises with the LocaleDropdownNavbarItem, if you have a setup as described above, then docusaurus by default makes the assumption that your defaultlocale is not part of the URL, and hence the logic is there if you switch the locale via the dropdown then they just add + on switching.
(Here I overcame this by swizzling the component and adding my own checks.)

Expected behavior

I would expect that docusaurus gives the configuration possibility for deploying with defaultlocale as part of the URL or not.

This issue relates to: #4723
(@slorber)
Is this related to #6075 as well?

Actual behavior

wrote it as part of description sorry.

Your environment

  • Public source code: Unfortunately not possible
  • Public site URL: https://docs.boc-group.com/adonis/en/
  • Docusaurus version used: beta-14
  • Environment name and version (e.g. Chrome 89, Node.js 16.4): latest
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS): Windows 10

Reproducible demo

Thank you

Self-service

  • I'd be willing to fix this bug myself.
@TomPeirs TomPeirs 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 Jan 24, 2022
@Josh-Cena Josh-Cena removed the status: needs triage This issue has not been triaged by maintainers label Jan 25, 2022
@Josh-Cena
Copy link
Collaborator

Docusaurus is right in assuming that "default locale isn't part of the base URL", since that's our current definition of default locale... What we want is #4723, i.e. completely getting rid of default locale

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 domain: i18n Related to the i18n system
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants