From 8df5d76e708238563185bac84809b34a4d395734 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sun, 26 Jan 2020 13:14:08 +0100 Subject: [PATCH] Fix 404 with base template regression Fixes #6795 --- hugolib/404_test.go | 16 ++++++++++++++++ hugolib/site_render.go | 12 +++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/hugolib/404_test.go b/hugolib/404_test.go index 5ea98be62..63a766d94 100644 --- a/hugolib/404_test.go +++ b/hugolib/404_test.go @@ -30,3 +30,19 @@ func Test404(t *testing.T) { b.AssertFileContent("public/404.html", "Not Found") } + +func Test404WithBase(t *testing.T) { + t.Parallel() + + b := newTestSitesBuilder(t) + b.WithSimpleConfigFile().WithTemplatesAdded("404.html", `{{ define "main" }} +Page not found +{{ end }}`) + 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", `Page not found`) + +} diff --git a/hugolib/site_render.go b/hugolib/site_render.go index a55cbb402..59f265996 100644 --- a/hugolib/site_render.go +++ b/hugolib/site_render.go @@ -251,7 +251,17 @@ func (s *Site) render404() error { return err } - templ := s.lookupLayouts("404.html") + var d output.LayoutDescriptor + d.Kind = kind404 + + templ, found, err := s.Tmpl().LookupLayout(d, output.HTMLFormat) + if err != nil { + return err + } + if !found { + return nil + } + targetPath := p.targetPaths().TargetFilename if targetPath == "" {