From 4c2a0de412a850745ad32e580fcd65575192ca53 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Fri, 21 Feb 2020 08:06:38 +0100 Subject: Fix panic in 404.Parent Fixes #6924 --- hugolib/404_test.go | 7 +++++-- hugolib/page__tree.go | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'hugolib') diff --git a/hugolib/404_test.go b/hugolib/404_test.go index a4dc667aa..6dea9295c 100644 --- a/hugolib/404_test.go +++ b/hugolib/404_test.go @@ -21,13 +21,16 @@ func Test404(t *testing.T) { t.Parallel() b := newTestSitesBuilder(t) - b.WithSimpleConfigFile().WithTemplatesAdded("404.html", "Not Found!") + b.WithSimpleConfigFile().WithTemplatesAdded("404.html", "Not Found! Parent: {{ .Parent.Kind }}") b.Build(BuildCfg{}) // Note: We currently have only 1 404 page. One might think that we should have // multiple, to follow the Custom Output scheme, but I don't see how that would work // right now. - b.AssertFileContent("public/404.html", "Not Found") + b.AssertFileContent("public/404.html", ` +Not Found +Parent: home +`) } diff --git a/hugolib/page__tree.go b/hugolib/page__tree.go index 08fda2289..2c3528922 100644 --- a/hugolib/page__tree.go +++ b/hugolib/page__tree.go @@ -121,11 +121,13 @@ func (pt pageTree) Parent() page.Page { return nil } - if pt.p.Kind() == page.KindTaxonomyTerm { + tree := p.getTreeRef() + + if pt.p.Kind() == page.KindTaxonomyTerm || tree == nil { return pt.p.s.home } - _, b := p.getTreeRef().getSection() + _, b := tree.getSection() if b == nil { return nil } -- cgit v1.2.3