diff options
author | Joe Mooring <[email protected]> | 2024-03-15 15:15:24 -0700 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2024-03-16 11:49:00 +0100 |
commit | 3935faa4175940dbd56b4e3a023163623b4bbdf2 (patch) | |
tree | 9c65127de454dd6a9d7c0fea7daeee313dc67a65 /hugolib/sitemap_test.go | |
parent | d4d49e0f0ec53ef7e105c51b5c6fd198c86acb7e (diff) | |
download | hugo-3935faa4175940dbd56b4e3a023163623b4bbdf2.tar.gz hugo-3935faa4175940dbd56b4e3a023163623b4bbdf2.zip |
hugolib: Fix sitemap index with monolingual site
Fixes #12266
Diffstat (limited to 'hugolib/sitemap_test.go')
-rw-r--r-- | hugolib/sitemap_test.go | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/hugolib/sitemap_test.go b/hugolib/sitemap_test.go index 6dad39fe3..a5a94c67e 100644 --- a/hugolib/sitemap_test.go +++ b/hugolib/sitemap_test.go @@ -15,6 +15,7 @@ package hugolib import ( "reflect" + "strings" "testing" "github.com/gohugoio/hugo/config" @@ -127,7 +128,7 @@ func TestParseSitemap(t *testing.T) { func TestSitemapShouldNotUseListXML(t *testing.T) { t.Parallel() - files := ` + files := ` -- hugo.toml -- baseURL = "https://example.com" disableKinds = ["term", "taxonomy"] @@ -170,3 +171,57 @@ type: sitemap b.AssertFileExists("public/sitemap.xml", true) } + +// Issue 12266 +func TestSitemapIssue12266(t *testing.T) { + t.Parallel() + + files := ` +-- hugo.toml -- +baseURL = 'https://example.org/' +disableKinds = ['rss','taxonomy','term'] +defaultContentLanguage = 'en' +defaultContentLanguageInSubdir = true +[languages.de] +[languages.en] + ` + + // Test A: multilingual with defaultContentLanguageInSubdir = true + b := Test(t, files) + + b.AssertFileContent("public/sitemap.xml", + "<loc>https://example.org/de/sitemap.xml</loc>", + "<loc>https://example.org/en/sitemap.xml</loc>", + ) + b.AssertFileContent("public/de/sitemap.xml", "<loc>https://example.org/de/</loc>") + b.AssertFileContent("public/en/sitemap.xml", "<loc>https://example.org/en/</loc>") + + // Test B: multilingual with defaultContentLanguageInSubdir = false + files = strings.ReplaceAll(files, "defaultContentLanguageInSubdir = true", "defaultContentLanguageInSubdir = false") + + b = Test(t, files) + + b.AssertFileContent("public/sitemap.xml", + "<loc>https://example.org/de/sitemap.xml</loc>", + "<loc>https://example.org/en/sitemap.xml</loc>", + ) + b.AssertFileContent("public/de/sitemap.xml", "<loc>https://example.org/de/</loc>") + b.AssertFileContent("public/en/sitemap.xml", "<loc>https://example.org/</loc>") + + // Test C: monolingual with defaultContentLanguageInSubdir = false + files = strings.ReplaceAll(files, "[languages.de]", "") + files = strings.ReplaceAll(files, "[languages.en]", "") + + b = Test(t, files) + + b.AssertFileExists("public/en/sitemap.xml", false) + b.AssertFileContent("public/sitemap.xml", "<loc>https://example.org/</loc>") + + // Test D: monolingual with defaultContentLanguageInSubdir = true + files = strings.ReplaceAll(files, "defaultContentLanguageInSubdir = false", "defaultContentLanguageInSubdir = true") + + b = Test(t, files) + + b.AssertFileContent("public/sitemap.xml", "<loc>https://example.org/en/sitemap.xml</loc>") + b.AssertFileContent("public/en/sitemap.xml", "<loc>https://example.org/en/</loc>") +} |