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 612e8f2 commit 6d616c2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
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
15 changes: 8 additions & 7 deletions hugolib/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -872,16 +872,17 @@ Param: svParamValue

}

func TestReproCommentsIn10953(t *testing.T) {
func TestConfigEmptyMainSections(t *testing.T) {
t.Parallel()

files := `
-- hugo.toml --
baseURL = "https://example.com"
disableKinds = ["taxonomy", "term", "RSS", "sitemap", "robotsTXT"]
-- hugo.yml --
params:
mainSections:
-- content/mysection/_index.md --
-- content/mysection/mycontent.md --
-- layouts/index.html --
{{ range first 1 .Params.images }}{{ end }}
mainSections: {{ site.Params.mainSections }}
`
b := NewIntegrationTestBuilder(
Expand All @@ -892,7 +893,7 @@ disableKinds = ["taxonomy", "term", "RSS", "sitemap", "robotsTXT"]
).Build()

b.AssertFileContent("public/index.html", `
mainSections: []
`)

}

0 comments on commit 6d616c2

Please sign in to comment.