diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-12-29 10:35:46 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-12-30 18:50:09 +0100 |
commit | 40ffb0484b96b7b77fb66202b33073b241807199 (patch) | |
tree | 6d9b9097b3adab78b3e07a257478d6e302944f1f /hugolib/page.go | |
parent | 4bae8b04aadd72d298bf2dd1bb1430806bf2869c (diff) |
hugolib: Restore 0.48 slash handling in taxonomies
Fixes #5571
Diffstat (limited to 'hugolib/page.go')
-rw-r--r-- | hugolib/page.go | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/hugolib/page.go b/hugolib/page.go index 15ed631c1..9f09dc9bd 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -2048,10 +2048,41 @@ func kindFromFileInfo(fi *fileInfo) string { return KindPage } +func (p *Page) sectionsPath() string { + if len(p.sections) == 0 { + return "" + } + if len(p.sections) == 1 { + return p.sections[0] + } + + return path.Join(p.sections...) +} + +func (p *Page) kindFromSections() string { + if len(p.sections) == 0 || len(p.s.Taxonomies) == 0 { + return KindSection + } + + sectionPath := p.sectionsPath() + + for k, _ := range p.s.Taxonomies { + if k == sectionPath { + return KindTaxonomyTerm + } + + if strings.HasPrefix(sectionPath, k) { + return KindTaxonomy + } + } + + return KindSection +} + func (p *Page) setValuesForKind(s *Site) { if p.Kind == kindUnknown { // This is either a taxonomy list, taxonomy term or a section - nodeType := s.kindFromSections(p.sections) + nodeType := p.kindFromSections() if nodeType == kindUnknown { panic(fmt.Sprintf("Unable to determine page kind from %q", p.sections)) |