Allow empty params.mainSections

Updates #10953
This commit is contained in:
Bjørn Erik Pedersen 2023-05-18 15:50:48 +02:00
parent 95818e27dc
commit 7c647bcaeb
4 changed files with 35 additions and 1 deletions

View file

@ -22,6 +22,7 @@ import (
"time" "time"
qt "github.com/frankban/quicktest" qt "github.com/frankban/quicktest"
"github.com/gohugoio/hugo/htesting"
"github.com/gohugoio/hugo/hugolib" "github.com/gohugoio/hugo/hugolib"
) )
@ -51,6 +52,10 @@ title: "Home"
} }
func TestPruneImages(t *testing.T) { func TestPruneImages(t *testing.T) {
if htesting.IsCI() {
// TODO(bep)
t.Skip("skip flaky test on CI server")
}
files := ` files := `
-- hugo.toml -- -- hugo.toml --
baseURL = "https://example.com" baseURL = "https://example.com"

View file

@ -367,7 +367,7 @@ type ConfigCompiled struct {
func (c *ConfigCompiled) SetMainSectionsIfNotSet(sections []string) { func (c *ConfigCompiled) SetMainSectionsIfNotSet(sections []string) {
c.mu.Lock() c.mu.Lock()
defer c.mu.Unlock() defer c.mu.Unlock()
if len(c.MainSections) > 0 { if c.MainSections != nil {
return return
} }
c.MainSections = sections c.MainSections = sections

View file

@ -177,6 +177,9 @@ var allDecoderSetups = map[string]decodeWeight{
// Before Hugo 0.112.0 this was configured via site Params. // Before Hugo 0.112.0 this was configured via site Params.
if mainSections, found := p.c.Params["mainsections"]; found { if mainSections, found := p.c.Params["mainsections"]; found {
p.c.MainSections = types.ToStringSlicePreserveString(mainSections) p.c.MainSections = types.ToStringSlicePreserveString(mainSections)
if p.c.MainSections == nil {
p.c.MainSections = []string{}
}
} }
return nil return nil

View file

@ -871,3 +871,29 @@ Param: svParamValue
`) `)
} }
func TestConfigEmptyMainSections(t *testing.T) {
t.Parallel()
files := `
-- hugo.yml --
params:
mainSections:
-- content/mysection/_index.md --
-- content/mysection/mycontent.md --
-- layouts/index.html --
mainSections: {{ site.Params.mainSections }}
`
b := NewIntegrationTestBuilder(
IntegrationTestConfig{
T: t,
TxtarString: files,
},
).Build()
b.AssertFileContent("public/index.html", `
mainSections: []
`)
}