summaryrefslogtreecommitdiffstats
path: root/hugolib/taxonomy.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-08-03 17:27:40 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-08-08 20:13:39 +0200
commit7ff0a8ee9fe8d710d407e57faf1fda43bd635f28 (patch)
tree4baa7d913f735cc1089e465b51ff007014bfe25a /hugolib/taxonomy.go
parentdf374851a0683f1446f33a4afef74c42f7d3eaaf (diff)
Simplify page tree logic
This is preparation for #6041. For historic reasons, the code for bulding the section tree and the taxonomies were very much separate. This works, but makes it hard to extend, maintain, and possibly not so fast as it could be. This simplification also introduces 3 slightly breaking changes, which I suspect most people will be pleased about. See referenced issues: This commit also switches the radix tree dependency to a mutable implementation: github.com/armon/go-radix. Fixes #6154 Fixes #6153 Fixes #6152
Diffstat (limited to 'hugolib/taxonomy.go')
-rw-r--r--hugolib/taxonomy.go94
1 files changed, 0 insertions, 94 deletions
diff --git a/hugolib/taxonomy.go b/hugolib/taxonomy.go
index a7965ec26..e3f033109 100644
--- a/hugolib/taxonomy.go
+++ b/hugolib/taxonomy.go
@@ -15,13 +15,11 @@ package hugolib
import (
"fmt"
- "path"
"sort"
"github.com/gohugoio/hugo/compare"
"github.com/gohugoio/hugo/resources/page"
- "github.com/gohugoio/hugo/resources/resource"
)
// The TaxonomyList is a list of all taxonomies and their values
@@ -156,95 +154,3 @@ func (s *orderedTaxonomySorter) Swap(i, j int) {
func (s *orderedTaxonomySorter) Less(i, j int) bool {
return s.by(&s.taxonomy[i], &s.taxonomy[j])
}
-
-// taxonomyNodeInfo stores additional metadata about a taxonomy.
-type taxonomyNodeInfo struct {
- plural string
-
- // Maps "tags" to "tag".
- singular string
-
- // The term key as used in the taxonomy map, e.g "tag1".
- // The value is normalized for paths, but may or not be lowercased
- // depending on the disablePathToLower setting.
- termKey string
-
- // The original, unedited term name. Useful for titles etc.
- term string
-
- dates resource.Dates
-
- parent *taxonomyNodeInfo
-
- // Either of Kind taxonomyTerm (parent) or taxonomy
- owner *page.PageWrapper
-}
-
-func (t *taxonomyNodeInfo) UpdateFromPage(p page.Page) {
-
- // Select the latest dates
- t.dates.UpdateDateAndLastmodIfAfter(p)
-}
-
-func (t *taxonomyNodeInfo) TransferValues(p *pageState) {
- t.owner.Page = p
- if p.Lastmod().IsZero() && p.Date().IsZero() {
- p.m.Dates.UpdateDateAndLastmodIfAfter(t.dates)
- }
-}
-
-// Maps either plural or plural/term to a taxonomy node.
-// TODO(bep) consolidate somehow with s.Taxonomies
-type taxonomyNodeInfos struct {
- m map[string]*taxonomyNodeInfo
- getKey func(string) string
-}
-
-// map[string]*taxonomyNodeInfo
-func (t taxonomyNodeInfos) key(parts ...string) string {
- return path.Join(parts...)
-}
-
-// GetOrAdd will get or create and add a new taxonomy node to the parent identified with plural.
-// It will panic if the parent does not exist.
-func (t taxonomyNodeInfos) GetOrAdd(plural, term string) *taxonomyNodeInfo {
- parent := t.GetOrCreate(plural, "")
- if parent == nil {
- panic(fmt.Sprintf("no parent found with plural %q", plural))
- }
- child := t.GetOrCreate(plural, term)
- child.parent = parent
- return child
-}
-
-func (t taxonomyNodeInfos) GetOrCreate(plural, term string) *taxonomyNodeInfo {
- termKey := t.getKey(term)
- key := t.key(plural, termKey)
-
- n, found := t.m[key]
- if found {
- return n
- }
-
- n = &taxonomyNodeInfo{
- plural: plural,
- termKey: termKey,
- term: term,
- owner: &page.PageWrapper{}, // Page will be assigned later.
- }
-
- t.m[key] = n
-
- return n
-}
-
-func (t taxonomyNodeInfos) Get(sections ...string) *taxonomyNodeInfo {
- key := t.key(sections...)
-
- n, found := t.m[key]
- if found {
- return n
- }
-
- return nil
-}