From b13180fcdae8da72da006d666dc7609985dfd40d Mon Sep 17 00:00:00 2001 From: Nicolas MASSE Date: Sun, 4 Oct 2026 10:42:04 +0200 Subject: [PATCH] fix SEO of the english articles published in the french site The canonical link and the noindex meta tag were never emitted on the english articles published as-is in the french site, because head.html was checking the language detection of the translation instead of the current page. Hence, the original articles also advertised the french copies as their translation through hreflang. - emit canonical + noindex on the french copies (68 pages) - only list real translations in hreflang, including the current page - exclude the french copies from the sitemap and its alternates - restrict the language detection to regular pages: list pages have no file and an empty content, hence they were always detected as copies Refs #11 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01YNHsWYTXPThURz6TbVS1j3 --- layouts/_default/sitemap.xml | 32 +++++++++++++++++++++++++ layouts/partials/head.html | 17 +++++++++---- layouts/partials/lang-detection.html | 2 +- layouts/partials/real-translations.html | 12 ++++++++++ 4 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 layouts/_default/sitemap.xml create mode 100644 layouts/partials/real-translations.html diff --git a/layouts/_default/sitemap.xml b/layouts/_default/sitemap.xml new file mode 100644 index 0000000..0f661f2 --- /dev/null +++ b/layouts/_default/sitemap.xml @@ -0,0 +1,32 @@ +{{- /* + -- Based on the Hugo embedded sitemap template (v0.121.2). + -- + -- The english articles published as-is in the french site are excluded + -- from the sitemap and from the list of alternates, since they are + -- duplicates of the original articles. + */ -}} +{{ printf "" | safeHTML }} + + {{ range $page := .Data.Pages }} + {{- partial "lang-detection.html" . -}} + {{- if and .Permalink (not (.Scratch.Get "en_article_in_fr_site")) -}} + + {{ .Permalink }}{{ if not .Lastmod.IsZero }} + {{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }}{{ end }}{{ with .Sitemap.ChangeFreq }} + {{ . }}{{ end }}{{ if ge .Sitemap.Priority 0.0 }} + {{ .Sitemap.Priority }}{{ end }}{{ with partial "real-translations.html" . }}{{ range . }} + {{ end }} + {{ end }} + + {{- end -}} + {{ end }} + diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 9721db1..a54f132 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -92,8 +92,6 @@ {{- partial "lang-detection.html" . -}} -{{- if .IsTranslated -}} -{{- range .Translations -}} {{- if .Scratch.Get "en_article_in_fr_site" -}} +{{- range first 1 .Translations }} +{{- end }} -{{ else }} - +{{- else -}} + +{{- with partial "real-translations.html" . -}} +{{- range . | append $ }} -{{ end -}} +{{- end -}} {{- end -}} {{- end -}} diff --git a/layouts/partials/lang-detection.html b/layouts/partials/lang-detection.html index a196a20..61b21ed 100644 --- a/layouts/partials/lang-detection.html +++ b/layouts/partials/lang-detection.html @@ -1,4 +1,4 @@ -{{ if and .IsTranslated (eq .Lang "fr") }} +{{ if and .IsPage .IsTranslated (eq .Lang "fr") }} {{ if and (index .AllTranslations 0).File (index .AllTranslations 1).File }} {{ $file0 := readFile (index .AllTranslations 0).File.Filename }} diff --git a/layouts/partials/real-translations.html b/layouts/partials/real-translations.html new file mode 100644 index 0000000..a3614b1 --- /dev/null +++ b/layouts/partials/real-translations.html @@ -0,0 +1,12 @@ +{{- /* + -- Returns the translations of a page, excluding the english articles + -- published as-is in the french site (they are not real translations). + */ -}} +{{- $translations := slice -}} +{{- range .Translations -}} + {{- partial "lang-detection.html" . -}} + {{- if not (.Scratch.Get "en_article_in_fr_site") -}} + {{- $translations = $translations | append . -}} + {{- end -}} +{{- end -}} +{{- return $translations -}}