Skip to content

Commit

Permalink
Allow empty params.mainSections
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed May 18, 2023
1 parent 3f00f47 commit 3e97a6b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/allconfig/allconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ type ConfigCompiled struct {
func (c *ConfigCompiled) SetMainSectionsIfNotSet(sections []string) {
c.mu.Lock()
defer c.mu.Unlock()
if len(c.MainSections) > 0 {
if c.MainSections != nil {
return
}
c.MainSections = sections
Expand Down
3 changes: 3 additions & 0 deletions config/allconfig/alldecoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ var allDecoderSetups = map[string]decodeWeight{
// Before Hugo 0.112.0 this was configured via site Params.
if mainSections, found := p.c.Params["mainsections"]; found {
p.c.MainSections = types.ToStringSlicePreserveString(mainSections)
if p.c.MainSections == nil {
p.c.MainSections = []string{}
}
}

return nil
Expand Down
26 changes: 26 additions & 0 deletions hugolib/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: []
`)

}

0 comments on commit 3e97a6b

Please sign in to comment.