Add hreflang logic and consolidate canonical partial
What does this MR do and why?
Implements hreflang tags for Japanese localization SEO and consolidates URL generation logic into a single partial.
Problem: Without hreflang tags, search engines can't understand language relationships between English and Japanese pages, potentially causing duplicate content penalties.
Solution:
- Detects when Japanese pages use English fallback content
- Generates appropriate hreflang tags based on translation availability
- Consolidates canonical and hreflang logic for maintainability
Hreflang Behavior
Fully translated pages:
<link rel="alternate" hreflang="en" href="https://docs.gitlab.com/page-path/" />
<link rel="alternate" hreflang="ja-jp" href="https://docs.gitlab.com/ja-jp/page-path/" />
<link rel="alternate" hreflang="x-default" href="https://docs.gitlab.com/page-path/" />
English fallback content:
<link rel="alternate" hreflang="en" href="https://docs.gitlab.com/page-path/" />
<link rel="alternate" hreflang="x-default" href="https://docs.gitlab.com/page-path/" />
<!-- No ja-jp hreflang since no translation exists -->
Changes
- Renamed canonical-url.html → canonical-hreflang.html
- Single loop processes all translations (performance improvement)
- Unified URL generation using consistent base URL
- Proper fallback content detection
Closes gitlab-com/localization/docs-site-localization#313 (closed)
Screenshots, screen recordings, or links to review app
These are strongly recommended to assist reviewers and reduce the time to merge your change.
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
- Configure a local GitLab Docs environment.
- Enable japanese site,
languages.ja-jp.disabled: falseinconfig/_default/hugo.yaml make view- Visit
ja-jpanden-usversions of page with full japanese translations. Verify correct canonical and hreflang. - Visit
ja-jpanden-usversions of page that utilized english fallback content on the Japanese version. Verify correct canonical and hreflang.
Merge request acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this merge request.