Fix 404 with base template regression
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 26 Jan 2020 12:14:08 +0000 (13:14 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 26 Jan 2020 12:14:08 +0000 (13:14 +0100)
Fixes #6795

hugolib/404_test.go
hugolib/site_render.go

index 5ea98be62b29dd991997a9c005093ad5d7d93969..63a766d941ee6437fc17195dc627222f9fde2cdd 100644 (file)
@@ -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`)
+
+}
index a55cbb402de3e3952f90e9d24900df2f02cd9726..59f26599628335029afc73ee5fbf66b067379149 100644 (file)
@@ -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 == "" {