From 475009fc6d1abcdd99abaa3e1c0a2cb8aa7718ea Mon Sep 17 00:00:00 2001 From: Patrice Chalin Date: Wed, 15 May 2024 14:20:45 -0400 Subject: [PATCH] [zh] Ensure zh fallback pages specify en page as canonical source --- layouts/partials/hooks/head-end.html | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/layouts/partials/hooks/head-end.html b/layouts/partials/hooks/head-end.html index 9b65af633442..df4552a026f3 100644 --- a/layouts/partials/hooks/head-end.html +++ b/layouts/partials/hooks/head-end.html @@ -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 -}} {{- end -}}