mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
parent
931e096f21
commit
7f3061723e
2 changed files with 61 additions and 14 deletions
|
@ -1881,11 +1881,19 @@ func (sa *sitePagesAssembler) addStandalonePages() error {
|
|||
}
|
||||
|
||||
if sitemapEnabled {
|
||||
addStandalone("/_sitemap", kinds.KindSitemap, output.SitemapFormat)
|
||||
skipSitemapIndex := s.Conf.IsMultihost() || !(s.Conf.DefaultContentLanguageInSubdir() || s.Conf.IsMultilingual())
|
||||
of := output.SitemapFormat
|
||||
if s.conf.Sitemap.Filename != "" {
|
||||
of.BaseName = paths.Filename(s.conf.Sitemap.Filename)
|
||||
}
|
||||
addStandalone("/_sitemap", kinds.KindSitemap, of)
|
||||
|
||||
skipSitemapIndex := s.Conf.IsMultihost() || !(s.Conf.DefaultContentLanguageInSubdir() || s.Conf.IsMultilingual())
|
||||
if !skipSitemapIndex {
|
||||
addStandalone("/_sitemapindex", kinds.KindSitemapIndex, output.SitemapIndexFormat)
|
||||
of = output.SitemapIndexFormat
|
||||
if s.conf.Sitemap.Filename != "" {
|
||||
of.BaseName = paths.Filename(s.conf.Sitemap.Filename)
|
||||
}
|
||||
addStandalone("/_sitemapindex", kinds.KindSitemapIndex, of)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ package hugolib
|
|||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
qt "github.com/frankban/quicktest"
|
||||
|
@ -358,3 +359,41 @@ p1-foo.txt
|
|||
b.AssertFileExists("public/s1/p1-foo.txt", true) // failing test
|
||||
b.AssertFileExists("public/s1/p1/index.html", true)
|
||||
}
|
||||
|
||||
func TestSitemapOverrideFilename(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
files := `
|
||||
-- hugo.toml --
|
||||
baseURL = 'https://example.org/'
|
||||
disableKinds = ['page','rss','section','taxonomy','term']
|
||||
defaultContentLanguage = 'de'
|
||||
defaultContentLanguageInSubdir = true
|
||||
[languages.de]
|
||||
[languages.en]
|
||||
[sitemap]
|
||||
filename = 'foo.xml'
|
||||
-- layouts/index.html --
|
||||
irrelevant
|
||||
`
|
||||
|
||||
b := Test(t, files)
|
||||
|
||||
b.AssertFileExists("public/de/foo.xml", true)
|
||||
b.AssertFileExists("public/en/foo.xml", true)
|
||||
b.AssertFileContent("public/foo.xml",
|
||||
"<loc>https://example.org/de/foo.xml</loc>",
|
||||
"<loc>https://example.org/en/foo.xml</loc>",
|
||||
)
|
||||
|
||||
files = strings.ReplaceAll(files, "filename = 'foo.xml'", "")
|
||||
|
||||
b = Test(t, files)
|
||||
|
||||
b.AssertFileExists("public/de/sitemap.xml", true)
|
||||
b.AssertFileExists("public/en/sitemap.xml", true)
|
||||
b.AssertFileContent("public/sitemap.xml",
|
||||
"<loc>https://example.org/de/sitemap.xml</loc>",
|
||||
"<loc>https://example.org/en/sitemap.xml</loc>",
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue