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:

  1. Detects when Japanese pages use English fallback content
  2. Generates appropriate hreflang tags based on translation availability
  3. 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

  1. Renamed canonical-url.html → canonical-hreflang.html
  2. Single loop processes all translations (performance improvement)
  3. Unified URL generation using consistent base URL
  4. 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.

  1. Configure a local GitLab Docs environment.
  2. Enable japanese site, languages.ja-jp.disabled: false in config/_default/hugo.yaml
  3. make view
  4. Visit ja-jp and en-us versions of page with full japanese translations. Verify correct canonical and hreflang.
  5. Visit ja-jp and en-us versions 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.

Merge request reports

Loading