Fix crashes for 404 in IsAncestor etc.

Fixes #6931
This commit is contained in:
Bjørn Erik Pedersen
2020-02-22 10:57:43 +01:00
parent c1eb625124
commit a524124beb
4 changed files with 64 additions and 6 deletions

View File

@@ -21,15 +21,41 @@ func Test404(t *testing.T) {
t.Parallel()
b := newTestSitesBuilder(t)
b.WithSimpleConfigFile().WithTemplatesAdded("404.html", "<html><body>Not Found! Parent: {{ .Parent.Kind }}</body></html>")
b.WithSimpleConfigFile().WithTemplatesAdded(
"404.html",
`
{{ $home := site.Home }}
404:
Parent: {{ .Parent.Kind }}
IsAncestor: {{ .IsAncestor $home }}/{{ $home.IsAncestor . }}
IsDescendant: {{ .IsDescendant $home }}/{{ $home.IsDescendant . }}
CurrentSection: {{ .CurrentSection.Kind }}|
FirstSection: {{ .FirstSection.Kind }}|
InSection: {{ .InSection $home.Section }}|{{ $home.InSection . }}
Sections: {{ len .Sections }}|
Page: {{ .Page.RelPermalink }}|
Data: {{ len .Data }}|
`,
)
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
404:
Parent: home
IsAncestor: false/true
IsDescendant: true/false
CurrentSection: home|
FirstSection: home|
InSection: false|true
Sections: 0|
Page: /404.html|
Data: 1|
`)
}