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