SEO: hreflang alternate link wrongful destination if baseURL contains defaultlocale. #6462
Open
6 of 7 tasks
Labels
bug
An error in the Docusaurus core causing instability or issues with its execution
domain: i18n
Related to the i18n system
Have you read the Contributing Guidelines on issues?
Prerequisites
npm run clear
oryarn clear
command.rm -rf node_modules yarn.lock package-lock.json
and re-installing packages.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
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",
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.** !! 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
Reproducible demo
Thank you
Self-service
The text was updated successfully, but these errors were encountered: