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

[zh] Ensure zh fallback pages specify en page as canonical source #4494

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions layouts/partials/hooks/head-end.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@

{{ $canonicalURL := .Permalink -}}

{{ $defaultLang := "en" -}}
{{ if and (ne .Language.Lang $defaultLang) .File -}}
{{/* This page is in a non-default-language section */ -}}
{{ $pagePath := strings.TrimPrefix (add hugo.WorkingDir "/content/") .File.Filename -}}
{{ if hasPrefix $pagePath $defaultLang -}}

{{/* This page is actually a default-language fallback page. Use the link
to the origin of the fallback page as canonical reference. */ -}}

{{ $translationPages := where .Translations "Lang" $defaultLang -}}
{{ $translation := index $translationPages 0 -}}
{{ with $translation -}}
{{ $canonicalURL = .Permalink -}}
{{ end -}}
{{ end -}}
{{ end -}}
<link rel="canonical" href="{{ $canonicalURL }}">

{{- end -}}