From 6475d308ec8ca17ad8950b3df3d01750c70acd48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 21 May 2026 19:44:23 +0200 Subject: [PATCH] tpl: Use AllTranslations in sitemap template Closes #14912 Closes #14917 --- hugolib/sitemap_test.go | 4 ++-- tpl/tplimpl/embedded/templates/sitemap.xml | 9 ++------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/hugolib/sitemap_test.go b/hugolib/sitemap_test.go index d8f10df83..5f536ecf2 100644 --- a/hugolib/sitemap_test.go +++ b/hugolib/sitemap_test.go @@ -80,8 +80,8 @@ Doc2 b := Test(t, files) b.AssertFileContent("public/sitemap.xml", "https://example.com/en/sitemap.xml", "https://example.com/nn/sitemap.xml") - b.AssertFileContent("public/en/sitemap.xml", " https://example.com/sect/doc1/", "doc2") - b.AssertFileContent("public/nn/sitemap.xml", " https://example.com/nn/sect/doc2/") + b.AssertFileContent("public/en/sitemap.xml", " https://example.com/sect/doc1/", "doc2", `hreflang="en"`, `hreflang="nn"`) + b.AssertFileContent("public/nn/sitemap.xml", " https://example.com/nn/sect/doc2/", `hreflang="en"`, `hreflang="nn"`) } // https://github.com/gohugoio/hugo/issues/5910 diff --git a/tpl/tplimpl/embedded/templates/sitemap.xml b/tpl/tplimpl/embedded/templates/sitemap.xml index d3539b190..bdedcacb1 100644 --- a/tpl/tplimpl/embedded/templates/sitemap.xml +++ b/tpl/tplimpl/embedded/templates/sitemap.xml @@ -8,17 +8,12 @@ {{ .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 }}{{ if .IsTranslated }}{{ range .Translations }} + {{ .Sitemap.Priority }}{{ end }}{{ $allTranslations := .AllTranslations }}{{ if gt ($allTranslations | len) 1 }}{{ range $allTranslations }} {{ end }} - {{ end }} + />{{ end }}{{ end }} {{- end -}} {{ end }}