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 -}}