Skip to content

Commit bc8a24b

Browse files
authored
[zh] Ensure zh fallback pages specify en page as canonical source (#4494)
1 parent 817c6eb commit bc8a24b

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

layouts/partials/hooks/head-end.html

+16
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@
66

77
{{ $canonicalURL := .Permalink -}}
88

9+
{{ $defaultLang := "en" -}}
10+
{{ if and (ne .Language.Lang $defaultLang) .File -}}
11+
{{/* This page is in a non-default-language section */ -}}
12+
{{ $pagePath := strings.TrimPrefix (add hugo.WorkingDir "/content/") .File.Filename -}}
13+
{{ if hasPrefix $pagePath $defaultLang -}}
14+
15+
{{/* This page is actually a default-language fallback page. Use the link
16+
to the origin of the fallback page as canonical reference. */ -}}
17+
18+
{{ $translationPages := where .Translations "Lang" $defaultLang -}}
19+
{{ $translation := index $translationPages 0 -}}
20+
{{ with $translation -}}
21+
{{ $canonicalURL = .Permalink -}}
22+
{{ end -}}
23+
{{ end -}}
24+
{{ end -}}
925
<link rel="canonical" href="{{ $canonicalURL }}">
1026

1127
{{- end -}}

0 commit comments

Comments
 (0)