aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2020-01-27 12:30:31 +0100
committerBjørn Erik Pedersen <[email protected]>2020-01-27 12:30:31 +0100
commit74b6c4e5ff5ee16f0e6b352a26c1e58b90a25dc6 (patch)
tree22c126aa60bd1cd01eed086df160c8bdd674d2e1
parent8df5d76e708238563185bac84809b34a4d395734 (diff)
downloadhugo-74b6c4e5ff5ee16f0e6b352a26c1e58b90a25dc6.tar.gz
hugo-74b6c4e5ff5ee16f0e6b352a26c1e58b90a25dc6.zip
And now finally fix the 404 templates
Fixes #6795
-rw-r--r--hugolib/404_test.go10
-rw-r--r--output/layout.go12
-rw-r--r--output/layout_test.go8
3 files changed, 21 insertions, 9 deletions
diff --git a/hugolib/404_test.go b/hugolib/404_test.go
index 63a766d94..a4dc667aa 100644
--- a/hugolib/404_test.go
+++ b/hugolib/404_test.go
@@ -35,14 +35,18 @@ func Test404WithBase(t *testing.T) {
t.Parallel()
b := newTestSitesBuilder(t)
- b.WithSimpleConfigFile().WithTemplatesAdded("404.html", `{{ define "main" }}
+ b.WithSimpleConfigFile().WithTemplates("404.html", `{{ define "main" }}
Page not found
-{{ end }}`)
+{{ end }}`,
+ "baseof.html", `Base: {{ block "main" . }}{{ end }}`).WithContent("page.md", ``)
+
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`)
+ b.AssertFileContent("public/404.html", `
+Base:
+Page not found`)
}
diff --git a/output/layout.go b/output/layout.go
index 0421e6f3d..e59404684 100644
--- a/output/layout.go
+++ b/output/layout.go
@@ -43,7 +43,7 @@ type LayoutDescriptor struct {
}
func (d LayoutDescriptor) isList() bool {
- return !d.RenderingHook && d.Kind != "page"
+ return !d.RenderingHook && d.Kind != "page" && d.Kind != "404"
}
// LayoutHandler calculates the layout template to use to render a given output type.
@@ -173,7 +173,9 @@ func resolvePageTemplate(d LayoutDescriptor, f Format) []string {
b.addTypeVariations("taxonomy")
b.addSectionType()
b.addLayoutVariations("terms")
-
+ case "404":
+ b.addLayoutVariations("404")
+ b.addTypeVariations("")
}
isRSS := f.Name == RSSFormat.Name
@@ -182,8 +184,10 @@ func resolvePageTemplate(d LayoutDescriptor, f Format) []string {
b.addLayoutVariations("")
}
- // All have _default in their lookup path
- b.addTypeVariations("_default")
+ if d.Baseof || d.Kind != "404" {
+ // Most have _default in their lookup path
+ b.addTypeVariations("_default")
+ }
if d.isList() {
// Add the common list type
diff --git a/output/layout_test.go b/output/layout_test.go
index 7efa5675f..8f26bb6c4 100644
--- a/output/layout_test.go
+++ b/output/layout_test.go
@@ -123,7 +123,11 @@ func TestLayout(t *testing.T) {
[]string{"section/shortcodes.amp.html"}, 12},
{"Reserved section, partials", LayoutDescriptor{Kind: "section", Section: "partials", Type: "partials"}, "", ampType,
[]string{"section/partials.amp.html"}, 12},
-
+ // This is currently always HTML only
+ {"404, HTML", LayoutDescriptor{Kind: "404"}, "", htmlFormat,
+ []string{"404.html.html", "404.html"}, 2},
+ {"404, HTML baseof", LayoutDescriptor{Kind: "404", Baseof: true}, "", htmlFormat,
+ []string{"404-baseof.html.html", "baseof.html.html", "404-baseof.html", "baseof.html", "_default/404-baseof.html.html", "_default/baseof.html.html", "_default/404-baseof.html", "_default/baseof.html"}, 8},
// We may add type support ... later.
{"Content hook", LayoutDescriptor{Kind: "render-link", RenderingHook: true, Layout: "mylayout", Section: "blog"}, "", ampType,
[]string{"_default/_markup/render-link.amp.html", "_default/_markup/render-link.html"}, 2},
@@ -134,7 +138,7 @@ func TestLayout(t *testing.T) {
layouts, err := l.For(this.d, this.tp)
c.Assert(err, qt.IsNil)
- c.Assert(layouts, qt.Not(qt.IsNil))
+ c.Assert(layouts, qt.Not(qt.IsNil), qt.Commentf(this.d.Kind))
c.Assert(len(layouts) >= len(this.expect), qt.Equals, true, qt.Commentf("%d vs %d", len(layouts), len(this.expect)))
// Not checking the complete list for now ...
got := layouts[:len(this.expect)]