hugolib: Fix panic for unused taxonomy content files

In Hugo 0.55 we connected the taxonomy nodes with their owning Page.

This failed if you had, say, a content file for a author that did not author anything in the site:

```
content/authors/silent-persin/_index.md
```

Fixes #5847
This commit is contained in:
Bjørn Erik Pedersen
2019-04-15 09:38:14 +02:00
parent 701486728e
commit b799b12f4a
5 changed files with 52 additions and 17 deletions

View File

@@ -94,7 +94,7 @@ type Site struct {
Taxonomies TaxonomyList
taxonomyNodes taxonomyNodeInfos
taxonomyNodes *taxonomyNodeInfos
Sections Taxonomy
Info SiteInfo
@@ -1566,24 +1566,23 @@ func (s *Site) assembleTaxonomies() error {
s.Taxonomies[plural] = make(Taxonomy)
}
s.taxonomyNodes = make(taxonomyNodeInfos)
s.taxonomyNodes = &taxonomyNodeInfos{
m: make(map[string]*taxonomyNodeInfo),
getKey: s.getTaxonomyKey,
}
s.Log.INFO.Printf("found taxonomies: %#v\n", taxonomies)
for singular, plural := range taxonomies {
parent := s.taxonomyNodes.GetOrCreate(plural, "", "")
parent := s.taxonomyNodes.GetOrCreate(plural, "")
parent.singular = singular
addTaxonomy := func(plural, term string, weight int, p page.Page) {
key := s.getTaxonomyKey(term)
n := s.taxonomyNodes.GetOrCreate(plural, key, term)
n := s.taxonomyNodes.GetOrCreate(plural, term)
n.parent = parent
// There may be different spellings before normalization, so the
// last one will win, e.g. "hugo" vs "Hugo".
n.term = term
w := page.NewWeightedPage(weight, p, n.owner)
s.Taxonomies[plural].add(key, w)