diff options
author | Bjørn Erik Pedersen <[email protected]> | 2020-02-22 10:57:43 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2020-02-22 13:36:04 +0100 |
commit | a524124beb0e7ca226c207ea48a90cea2cbef76e (patch) | |
tree | cf15663aa62b698b32aaf10d2573a7bce0188743 /hugolib/page__tree.go | |
parent | c1eb62512446fd80ff5e4c0f45c8614788595e0e (diff) | |
download | hugo-a524124beb0e7ca226c207ea48a90cea2cbef76e.tar.gz hugo-a524124beb0e7ca226c207ea48a90cea2cbef76e.zip |
Fix crashes for 404 in IsAncestor etc.
Fixes #6931
Diffstat (limited to 'hugolib/page__tree.go')
-rw-r--r-- | hugolib/page__tree.go | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/hugolib/page__tree.go b/hugolib/page__tree.go index 2c3528922..bd7b586b9 100644 --- a/hugolib/page__tree.go +++ b/hugolib/page__tree.go @@ -37,6 +37,15 @@ func (pt pageTree) IsAncestor(other interface{}) (bool, error) { ref1, ref2 := pt.p.getTreeRef(), tp.getTreeRef() + if ref1 == nil || ref2 == nil { + if ref1 == nil { + // A 404 or other similar standalone page. + return false, nil + } + + return ref1.n.p.IsHome(), nil + } + if !ref1.isSection() { return false, nil } @@ -66,6 +75,15 @@ func (pt pageTree) IsDescendant(other interface{}) (bool, error) { ref1, ref2 := pt.p.getTreeRef(), tp.getTreeRef() + if ref1 == nil || ref2 == nil { + if ref2 == nil { + // A 404 or other similar standalone page. + return false, nil + } + + return ref2.n.p.IsHome(), nil + } + if !ref2.isSection() { return false, nil } @@ -76,6 +94,9 @@ func (pt pageTree) IsDescendant(other interface{}) (bool, error) { func (pt pageTree) FirstSection() page.Page { ref := pt.p.getTreeRef() + if ref == nil { + return pt.p.s.home + } key := ref.key if !ref.isSection() { key = path.Dir(key) @@ -99,6 +120,14 @@ func (pt pageTree) InSection(other interface{}) (bool, error) { ref1, ref2 := pt.p.getTreeRef(), tp.getTreeRef() + if ref1 == nil || ref2 == nil { + if ref1 == nil { + // A 404 or other similar standalone page. + return false, nil + } + return ref1.n.p.IsHome(), nil + } + s1, _ := ref1.getCurrentSection() s2, _ := ref2.getCurrentSection() @@ -123,7 +152,7 @@ func (pt pageTree) Parent() page.Page { tree := p.getTreeRef() - if pt.p.Kind() == page.KindTaxonomyTerm || tree == nil { + if tree == nil || pt.p.Kind() == page.KindTaxonomyTerm { return pt.p.s.home } |