summaryrefslogtreecommitdiffstats
path: root/hugolib/hugo_sites.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-04-15 09:38:14 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-04-15 13:36:05 +0200
commitb799b12f4a693dfeae8a5a362f131081a727bb8f (patch)
treecec0b90c41aea0f091ac5aa8dc72fc7380f78253 /hugolib/hugo_sites.go
parent701486728e21bc0c6c78c2a8edb988abdf6116c7 (diff)
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
Diffstat (limited to 'hugolib/hugo_sites.go')
-rw-r--r--hugolib/hugo_sites.go16
1 files changed, 15 insertions, 1 deletions
diff --git a/hugolib/hugo_sites.go b/hugolib/hugo_sites.go
index 8c80e189c..6f95dbb12 100644
--- a/hugolib/hugo_sites.go
+++ b/hugolib/hugo_sites.go
@@ -14,7 +14,9 @@
package hugolib
import (
+ "fmt"
"io"
+ "path"
"path/filepath"
"sort"
"strings"
@@ -650,7 +652,19 @@ func (h *HugoSites) createMissingPages() error {
// Make them navigable from WeightedPage etc.
for _, p := range taxonomyPages {
- p.getTaxonomyNodeInfo().TransferValues(p)
+ ni := p.getTaxonomyNodeInfo()
+ if ni == nil {
+ // This can be nil for taxonomies, e.g. an author,
+ // with a content file, but no actual usage.
+ // Create one.
+ sections := p.SectionsEntries()
+ if len(sections) < 2 {
+ // Invalid state
+ panic(fmt.Sprintf("invalid taxonomy state for %q with sections %v", p.pathOrTitle(), sections))
+ }
+ ni = p.s.taxonomyNodes.GetOrAdd(sections[0], path.Join(sections[1:]...))
+ }
+ ni.TransferValues(p)
}
for _, p := range taxonomyTermsPages {
p.getTaxonomyNodeInfo().TransferValues(p)