tpl: Make any layout set in front matter higher priority

Fixes #13541
This commit is contained in:
Bjørn Erik Pedersen
2025-04-12 12:37:39 +02:00
parent c8710625b7
commit 30b9c19c76
7 changed files with 128 additions and 102 deletions

View File

@@ -510,7 +510,7 @@ baseof: {{ block "main" . }}{{ end }}
q := tplimpl.TemplateQuery{
Path: "/baz",
Category: tplimpl.CategoryLayout,
Desc: tplimpl.TemplateDescriptor{Kind: kinds.KindPage, Layout: "single", OutputFormat: "html"},
Desc: tplimpl.TemplateDescriptor{Kind: kinds.KindPage, LayoutFromTemplate: "single", OutputFormat: "html"},
}
for i := 0; i < b.N; i++ {
store.LookupPagesLayout(q)
@@ -521,7 +521,7 @@ baseof: {{ block "main" . }}{{ end }}
q := tplimpl.TemplateQuery{
Path: "/foo/bar",
Category: tplimpl.CategoryLayout,
Desc: tplimpl.TemplateDescriptor{Kind: kinds.KindPage, Layout: "single", OutputFormat: "html"},
Desc: tplimpl.TemplateDescriptor{Kind: kinds.KindPage, LayoutFromTemplate: "single", OutputFormat: "html"},
}
for i := 0; i < b.N; i++ {
store.LookupPagesLayout(q)
@@ -648,9 +648,6 @@ layout: mylayout
b := hugolib.Test(t, files, hugolib.TestOptWarn())
// s := b.H.Sites[0].TemplateStore
// s.PrintDebug("", tplimpl.CategoryLayout, os.Stdout)
b.AssertLogContains("! WARN")
// Single pages.
@@ -1095,6 +1092,41 @@ s2.
})
}
func TestStandardLayoutInFrontMatter13588(t *testing.T) {
t.Parallel()
files := `
-- hugo.toml --
disableKinds = ['home','page','rss','sitemap','taxonomy','term']
-- content/s1/_index.md --
---
title: s1
---
-- content/s2/_index.md --
---
title: s2
layout: list
---
-- content/s3/_index.md --
---
title: s3
layout: single
---
-- layouts/list.html --
list.html
-- layouts/section.html --
section.html
-- layouts/single.html --
single.html
`
b := hugolib.Test(t, files)
b.AssertFileContent("public/s1/index.html", "section.html")
b.AssertFileContent("public/s2/index.html", "list.html") // fail
b.AssertFileContent("public/s3/index.html", "single.html") // fail
}
func TestSkipDotFiles(t *testing.T) {
t.Parallel()