Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6475d30

Browse files
committed
tpl: Use AllTranslations in sitemap template
Closes #14912 Closes #14917
1 parent 67aede4 commit 6475d30

2 files changed

Lines changed: 4 additions & 9 deletions

File tree

hugolib/sitemap_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ Doc2
8080
b := Test(t, files)
8181

8282
b.AssertFileContent("public/sitemap.xml", "<loc>https://example.com/en/sitemap.xml</loc>", "<loc>https://example.com/nn/sitemap.xml</loc>")
83-
b.AssertFileContent("public/en/sitemap.xml", " <loc>https://example.com/sect/doc1/</loc>", "doc2")
84-
b.AssertFileContent("public/nn/sitemap.xml", " <loc>https://example.com/nn/sect/doc2/</loc>")
83+
b.AssertFileContent("public/en/sitemap.xml", " <loc>https://example.com/sect/doc1/</loc>", "doc2", `hreflang="en"`, `hreflang="nn"`)
84+
b.AssertFileContent("public/nn/sitemap.xml", " <loc>https://example.com/nn/sect/doc2/</loc>", `hreflang="en"`, `hreflang="nn"`)
8585
}
8686

8787
// https://github.com/gohugoio/hugo/issues/5910

tpl/tplimpl/embedded/templates/sitemap.xml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,12 @@
88
<loc>{{ .Permalink }}</loc>{{ if not .Lastmod.IsZero }}
99
<lastmod>{{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }}</lastmod>{{ end }}{{ with .Sitemap.ChangeFreq }}
1010
<changefreq>{{ . }}</changefreq>{{ end }}{{ if ge .Sitemap.Priority 0.0 }}
11-
<priority>{{ .Sitemap.Priority }}</priority>{{ end }}{{ if .IsTranslated }}{{ range .Translations }}
11+
<priority>{{ .Sitemap.Priority }}</priority>{{ end }}{{ $allTranslations := .AllTranslations }}{{ if gt ($allTranslations | len) 1 }}{{ range $allTranslations }}
1212
<xhtml:link
1313
rel="alternate"
1414
hreflang="{{ .Language.Locale }}"
1515
href="{{ .Permalink }}"
16-
/>{{ end }}
17-
<xhtml:link
18-
rel="alternate"
19-
hreflang="{{ .Language.Locale }}"
20-
href="{{ .Permalink }}"
21-
/>{{ end }}
16+
/>{{ end }}{{ end }}
2217
</url>
2318
{{- end -}}
2419
{{ end }}

0 commit comments

Comments
 (0)