hugolib: Add .Site.Params.mainSections

Fixes #3206
This commit is contained in:
Bjørn Erik Pedersen
2017-04-07 13:03:34 +02:00
parent 5714531f34
commit 7ad721fd78
2 changed files with 37 additions and 0 deletions

View File

@@ -1698,6 +1698,36 @@ func (s *Site) assembleSections() {
wp.Page.PrevInSection = s.Sections[k][i+1].Page
}
}
}
var (
sectionsParamId = "mainSections"
sectionsParamIdLower = strings.ToLower(sectionsParamId)
mainSections interface{}
found bool
)
if mainSections, found = s.Info.Params[sectionsParamIdLower]; !found {
// Pick the section with most regular pages
var (
chosenSection string
pageCount int
)
for sect, pages := range s.Sections {
if pages.Count() >= pageCount {
chosenSection = sect
pageCount = pages.Count()
}
}
mainSections = []string{chosenSection}
// Try to make this as backwards compatible as possible.
s.Info.Params[sectionsParamId] = mainSections
s.Info.Params[sectionsParamIdLower] = mainSections
} else {
s.Info.Params[sectionsParamId] = mainSections
}
}