@@ -16,6 +16,7 @@ package hugolib
1616import (
1717 "fmt"
1818 "path/filepath"
19+ "strings"
1920 "testing"
2021
2122 qt "github.com/frankban/quicktest"
@@ -27,7 +28,7 @@ func TestContentMapSite(t *testing.T) {
2728 pageTempl := `
2829---
2930title: "Page %d"
30- date: "2019-06-0%d"
31+ date: "2019-06-0%d"
3132lastMod: "2019-06-0%d"
3233categories: [%q]
3334---
@@ -54,7 +55,7 @@ draft: true
5455title: "Hugo Home"
5556cascade:
5657 description: "Common Description"
57-
58+
5859---
5960
6061Home Content.
@@ -110,7 +111,7 @@ IsDescendant overlap2: false: {{ $overlap2.IsDescendant $overlap1 }}
110111IsAncestor overlap1: false: {{ $overlap1.IsAncestor $overlap2 }}
111112IsAncestor overlap2: false: {{ $overlap2.IsAncestor $overlap1 }}
112113FirstSection: {{ $blogSub.FirstSection.RelPermalink }} {{ $blog.FirstSection.RelPermalink }} {{ $home.FirstSection.RelPermalink }} {{ $page.FirstSection.RelPermalink }}
113- InSection: true: {{ $page.InSection $blog }} false: {{ $page.InSection $blogSub }}
114+ InSection: true: {{ $page.InSection $blog }} false: {{ $page.InSection $blogSub }}
114115Next: {{ $page2.Next.RelPermalink }}
115116NextInSection: {{ $page2.NextInSection.RelPermalink }}
116117Pages: {{ range $blog.Pages }}{{ .RelPermalink }}|{{ end }}
@@ -140,11 +141,11 @@ Draft5: {{ if (.Site.GetPage "blog/draftsection/sub/page") }}FOUND{{ end }}|
140141 Num Regular: 9
141142 Main Sections: [blog]
142143 Pag Num Pages: 9
143-
144- Home: Hugo Home|/|2019-06-08|Current Section: /|Resources:
145- Blog Section: Blogs|/blog/|2019-06-08|Current Section: /blog|Resources:
144+
145+ Home: Hugo Home|/|2019-06-08|Current Section: /|Resources:
146+ Blog Section: Blogs|/blog/|2019-06-08|Current Section: /blog|Resources:
146147 Blog Sub Section: Page 3|/blog/subsection/|2019-06-03|Current Section: /blog/subsection|Resources: application: /blog/subsection/subdata.json|
147- Page: Page 1|/blog/page1/|2019-06-01|Current Section: /blog|Resources:
148+ Page: Page 1|/blog/page1/|2019-06-01|Current Section: /blog|Resources:
148149 Bundle: Page 12|/blog/bundle/|0001-01-01|Current Section: /blog|Resources: application: /blog/bundle/data.json|page: |
149150 IsDescendant: true: true true: true true: true true: true true: true false: false false: false
150151 IsAncestor: true: true true: true true: true true: true true: true true: true false: false false: false false: false false: false
@@ -153,7 +154,7 @@ Draft5: {{ if (.Site.GetPage "blog/draftsection/sub/page") }}FOUND{{ end }}|
153154 IsAncestor overlap1: false: false
154155 IsAncestor overlap2: false: false
155156 FirstSection: /blog/ /blog/ / /blog/
156- InSection: true: true false: false
157+ InSection: true: true false: false
157158 Next: /blog/page3/
158159 NextInSection: /blog/page3/
159160 Pages: /blog/page3/|/blog/subsection/|/blog/page2/|/blog/page1/|/blog/bundle/|
@@ -165,13 +166,13 @@ Draft5: {{ if (.Site.GetPage "blog/draftsection/sub/page") }}FOUND{{ end }}|
165166 Pag Blog Num Pages: 4
166167 Blog Num RegularPages: 4
167168 Blog Num Pages: 5
168-
169+
169170 Draft1: |
170171 Draft2: FOUND|
171172 Draft3: FOUND|
172173 Draft4: FOUND|
173174 Draft5: FOUND|
174-
175+
175176` )
176177}
177178
@@ -185,7 +186,7 @@ title = "Integration Test"
185186disableKinds=["page", "section", "taxonomy", "term", "sitemap", "robotsTXT", "RSS"]
186187-- layouts/index.html --
187188Home: {{ .Title }}|
188-
189+
189190 `
190191
191192 b := NewIntegrationTestBuilder (
@@ -358,3 +359,41 @@ p1-foo.txt
358359 b .AssertFileExists ("public/s1/p1-foo.txt" , true ) // failing test
359360 b .AssertFileExists ("public/s1/p1/index.html" , true )
360361}
362+
363+ func TestSitemapOverrideFilename (t * testing.T ) {
364+ t .Parallel ()
365+
366+ files := `
367+ -- hugo.toml --
368+ baseURL = 'https://example.org/'
369+ disableKinds = ['page','rss','section','taxonomy','term']
370+ defaultContentLanguage = 'de'
371+ defaultContentLanguageInSubdir = true
372+ [languages.de]
373+ [languages.en]
374+ [sitemap]
375+ filename = 'foo.xml'
376+ -- layouts/index.html --
377+ irrelevant
378+ `
379+
380+ b := Test (t , files )
381+
382+ b .AssertFileExists ("public/de/foo.xml" , true )
383+ b .AssertFileExists ("public/en/foo.xml" , true )
384+ b .AssertFileContent ("public/foo.xml" ,
385+ "<loc>https://example.org/de/foo.xml</loc>" ,
386+ "<loc>https://example.org/en/foo.xml</loc>" ,
387+ )
388+
389+ files = strings .ReplaceAll (files , "filename = 'foo.xml'" , "" )
390+
391+ b = Test (t , files )
392+
393+ b .AssertFileExists ("public/de/sitemap.xml" , true )
394+ b .AssertFileExists ("public/en/sitemap.xml" , true )
395+ b .AssertFileContent ("public/sitemap.xml" ,
396+ "<loc>https://example.org/de/sitemap.xml</loc>" ,
397+ "<loc>https://example.org/en/sitemap.xml</loc>" ,
398+ )
399+ }
0 commit comments