mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-22 21:42:50 +02:00
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:
@@ -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)
|
||||
|
Reference in New Issue
Block a user