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
No known key found for this signature in database
7 changed files with 128 additions and 102 deletions

View file

@ -53,7 +53,7 @@ func (a aliasHandler) renderAlias(permalink string, p page.Page) (io.Reader, err
if ps, ok := p.(*pageState); ok { if ps, ok := p.(*pageState); ok {
base, templateDesc = ps.GetInternalTemplateBasePathAndDescriptor() base, templateDesc = ps.GetInternalTemplateBasePathAndDescriptor()
} }
templateDesc.Layout = "" templateDesc.LayoutFromUser = ""
templateDesc.Kind = "" templateDesc.Kind = ""
templateDesc.OutputFormat = output.AliasHTMLFormat.Name templateDesc.OutputFormat = output.AliasHTMLFormat.Name

View file

@ -538,6 +538,7 @@ title: p1
-- content/p1/c.html -- -- content/p1/c.html --
<p>c</p> <p>c</p>
-- layouts/_default/single.html -- -- layouts/_default/single.html --
Path: {{ .Path }}|{{.Kind }}
|{{ (.Resources.Get "a.html").RelPermalink -}} |{{ (.Resources.Get "a.html").RelPermalink -}}
|{{ (.Resources.Get "b.html").RelPermalink -}} |{{ (.Resources.Get "b.html").RelPermalink -}}
|{{ (.Resources.Get "c.html").Publish }} |{{ (.Resources.Get "c.html").Publish }}

View file

@ -482,12 +482,12 @@ func (po *pageOutput) GetInternalTemplateBasePathAndDescriptor() (string, tplimp
f := po.f f := po.f
base := p.PathInfo().BaseReTyped(p.m.pageConfig.Type) base := p.PathInfo().BaseReTyped(p.m.pageConfig.Type)
return base, tplimpl.TemplateDescriptor{ return base, tplimpl.TemplateDescriptor{
Kind: p.Kind(), Kind: p.Kind(),
Lang: p.Language().Lang, Lang: p.Language().Lang,
Layout: p.Layout(), LayoutFromUser: p.Layout(),
OutputFormat: f.Name, OutputFormat: f.Name,
MediaType: f.MediaType.Type, MediaType: f.MediaType.Type,
IsPlainText: f.IsPlainText, IsPlainText: f.IsPlainText,
} }
} }
@ -495,8 +495,8 @@ func (p *pageState) resolveTemplate(layouts ...string) (*tplimpl.TemplInfo, bool
dir, d := p.GetInternalTemplateBasePathAndDescriptor() dir, d := p.GetInternalTemplateBasePathAndDescriptor()
if len(layouts) > 0 { if len(layouts) > 0 {
d.Layout = layouts[0] d.LayoutFromUser = layouts[0]
d.LayoutMustMatch = true d.LayoutFromUserMustMatch = true
} }
q := tplimpl.TemplateQuery{ q := tplimpl.TemplateQuery{

View file

@ -22,8 +22,9 @@ const baseNameBaseof = "baseof"
// This is used both as a key and in lookups. // This is used both as a key and in lookups.
type TemplateDescriptor struct { type TemplateDescriptor struct {
// Group 1. // Group 1.
Kind string // page, home, section, taxonomy, term (and only those) Kind string // page, home, section, taxonomy, term (and only those)
Layout string // list, single, baseof, mycustomlayout. LayoutFromTemplate string // list, single, all,mycustomlayout
LayoutFromUser string // custom layout set in front matter, e.g. list, single, all, mycustomlayout
// Group 2. // Group 2.
OutputFormat string // rss, csv ... OutputFormat string // rss, csv ...
@ -34,23 +35,21 @@ type TemplateDescriptor struct {
Variant2 string // contextual variant, e.g. "id" in render. Variant2 string // contextual variant, e.g. "id" in render.
// Misc. // Misc.
LayoutMustMatch bool // If set, we only look for the exact layout. LayoutFromUserMustMatch bool // If set, we only look for the exact layout.
IsPlainText bool // Whether this is a plain text template. IsPlainText bool // Whether this is a plain text template.
} }
func (d *TemplateDescriptor) normalizeFromFile() { func (d *TemplateDescriptor) normalizeFromFile() {
// fmt.Println("normalizeFromFile", "kind:", d.Kind, "layout:", d.Layout, "of:", d.OutputFormat) if d.LayoutFromTemplate == d.OutputFormat {
d.LayoutFromTemplate = ""
if d.Layout == d.OutputFormat {
d.Layout = ""
} }
if d.Kind == kinds.KindTemporary { if d.Kind == kinds.KindTemporary {
d.Kind = "" d.Kind = ""
} }
if d.Layout == d.Kind { if d.LayoutFromTemplate == d.Kind {
d.Layout = "" d.LayoutFromTemplate = ""
} }
} }
@ -61,7 +60,7 @@ type descriptorHandler struct {
// Note that this in this setup is usually a descriptor constructed from a page, // Note that this in this setup is usually a descriptor constructed from a page,
// so we want to find the best match for that page. // so we want to find the best match for that page.
func (s descriptorHandler) compareDescriptors(category Category, isEmbedded bool, this, other TemplateDescriptor) weight { func (s descriptorHandler) compareDescriptors(category Category, isEmbedded bool, this, other TemplateDescriptor) weight {
if this.LayoutMustMatch && this.Layout != other.Layout { if this.LayoutFromUserMustMatch && this.LayoutFromUser != other.LayoutFromTemplate {
return weightNoMatch return weightNoMatch
} }
@ -94,20 +93,15 @@ func (this TemplateDescriptor) doCompare(category Category, isEmbedded bool, oth
return w return w
} }
if other.Layout != "" && other.Layout != layoutAll && other.Layout != this.Layout { if other.LayoutFromTemplate != "" && other.LayoutFromTemplate != layoutAll {
if isLayoutCustom(this.Layout) { if this.LayoutFromUser == "" {
if this.Kind == "" { if other.LayoutFromTemplate != this.LayoutFromTemplate {
this.Layout = "" return w
} else if this.Kind == kinds.KindPage { }
this.Layout = layoutSingle } else if isLayoutStandard(this.LayoutFromUser) {
} else { if other.LayoutFromTemplate != this.LayoutFromUser {
this.Layout = layoutList return w
} }
}
// Test again.
if other.Layout != this.Layout {
return w
} }
} }
@ -123,7 +117,11 @@ func (this TemplateDescriptor) doCompare(category Category, isEmbedded bool, oth
// We want e.g. home page in amp output format (media type text/html) to // We want e.g. home page in amp output format (media type text/html) to
// find a template even if one isn't specified for that output format, // find a template even if one isn't specified for that output format,
// when one exist for the html output format (same media type). // when one exist for the html output format (same media type).
if category != CategoryBaseof && (this.Kind == "" || (this.Kind != other.Kind && (this.Layout != other.Layout && other.Layout != layoutAll))) { skip := category != CategoryBaseof && (this.Kind == "" || (this.Kind != other.Kind && (this.LayoutFromTemplate != other.LayoutFromTemplate && other.LayoutFromTemplate != layoutAll)))
if this.LayoutFromUser != "" {
skip = skip && (this.LayoutFromUser != other.LayoutFromTemplate)
}
if skip {
return w return w
} }
@ -148,14 +146,14 @@ func (this TemplateDescriptor) doCompare(category Category, isEmbedded bool, oth
} }
const ( const (
weightKind = 3 // page, home, section, taxonomy, term (and only those) weightKind = 3 // page, home, section, taxonomy, term (and only those)
weightcustomLayout = 4 // custom layout (mylayout, set in e.g. front matter) weightcustomLayout = 4 // custom layout (mylayout, set in e.g. front matter)
weightLayout = 2 // standard layouts (single,list,all) weightLayoutStandard = 2 // standard layouts (single,list,all)
weightOutputFormat = 2 // a configured output format (e.g. rss, html, json) weightOutputFormat = 2 // a configured output format (e.g. rss, html, json)
weightMediaType = 1 // a configured media type (e.g. text/html, text/plain) weightMediaType = 1 // a configured media type (e.g. text/html, text/plain)
weightLang = 1 // a configured language (e.g. en, nn, fr, ...) weightLang = 1 // a configured language (e.g. en, nn, fr, ...)
weightVariant1 = 4 // currently used for render hooks, e.g. "link", "image" weightVariant1 = 4 // currently used for render hooks, e.g. "link", "image"
weightVariant2 = 2 // currently used for render hooks, e.g. the language "go" in code blocks. weightVariant2 = 2 // currently used for render hooks, e.g. the language "go" in code blocks.
// We will use the values for group 2 and 3 // We will use the values for group 2 and 3
// if the distance up to the template is shorter than // if the distance up to the template is shorter than
@ -179,14 +177,16 @@ func (this TemplateDescriptor) doCompare(category Category, isEmbedded bool, oth
w.w2 = weight2Group1 w.w2 = weight2Group1
} }
if other.Layout != "" && other.Layout == this.Layout || other.Layout == layoutAll { if this.LayoutFromUser == "" && other.LayoutFromTemplate != "" && (other.LayoutFromTemplate == this.LayoutFromTemplate || other.LayoutFromTemplate == layoutAll) {
if isLayoutCustom(this.Layout) { w.w1 += weightLayoutStandard
w.w1 += weightcustomLayout w.w2 = weight2Group1
w.w2 = weight2Group2
} else { }
w.w1 += weightLayout
w.w2 = weight2Group1 // LayoutCustom is only set in this (usually from Page.Layout).
} if this.LayoutFromUser != "" && this.LayoutFromUser == other.LayoutFromTemplate {
w.w1 += weightcustomLayout
w.w2 = weight2Group2
} }
if other.Lang != "" && other.Lang == this.Lang { if other.Lang != "" && other.Lang == this.Lang {

View file

@ -38,29 +38,29 @@ func TestTemplateDescriptorCompare(t *testing.T) {
check( check(
CategoryBaseof, CategoryBaseof,
TemplateDescriptor{Kind: "", Layout: "", Lang: "", OutputFormat: "404", MediaType: "text/html"}, TemplateDescriptor{Kind: "", LayoutFromTemplate: "", Lang: "", OutputFormat: "404", MediaType: "text/html"},
TemplateDescriptor{Kind: "", Layout: "", Lang: "", OutputFormat: "html", MediaType: "text/html"}, TemplateDescriptor{Kind: "", LayoutFromTemplate: "", Lang: "", OutputFormat: "html", MediaType: "text/html"},
false, false,
) )
check( check(
CategoryLayout, CategoryLayout,
TemplateDescriptor{Kind: "", Lang: "en", OutputFormat: "404", MediaType: "text/html"}, TemplateDescriptor{Kind: "", Lang: "en", OutputFormat: "404", MediaType: "text/html"},
TemplateDescriptor{Kind: "", Layout: "", Lang: "", OutputFormat: "alias", MediaType: "text/html"}, TemplateDescriptor{Kind: "", LayoutFromTemplate: "", Lang: "", OutputFormat: "alias", MediaType: "text/html"},
true, true,
) )
less( less(
CategoryLayout, CategoryLayout,
TemplateDescriptor{Kind: kinds.KindHome, Layout: "list", OutputFormat: "html"}, TemplateDescriptor{Kind: kinds.KindHome, LayoutFromTemplate: "list", OutputFormat: "html"},
TemplateDescriptor{Layout: "list", OutputFormat: "html"}, TemplateDescriptor{LayoutFromTemplate: "list", OutputFormat: "html"},
TemplateDescriptor{Kind: kinds.KindHome, OutputFormat: "html"}, TemplateDescriptor{Kind: kinds.KindHome, OutputFormat: "html"},
) )
check( check(
CategoryLayout, CategoryLayout,
TemplateDescriptor{Kind: kinds.KindHome, Layout: "list", OutputFormat: "html", MediaType: "text/html"}, TemplateDescriptor{Kind: kinds.KindHome, LayoutFromTemplate: "list", OutputFormat: "html", MediaType: "text/html"},
TemplateDescriptor{Kind: kinds.KindHome, Layout: "list", OutputFormat: "myformat", MediaType: "text/html"}, TemplateDescriptor{Kind: kinds.KindHome, LayoutFromTemplate: "list", OutputFormat: "myformat", MediaType: "text/html"},
false, false,
) )
} }
@ -78,20 +78,20 @@ func BenchmarkCompareDescriptors(b *testing.B) {
d1, d2 TemplateDescriptor d1, d2 TemplateDescriptor
}{ }{
{ {
TemplateDescriptor{Kind: "", Layout: "", OutputFormat: "404", MediaType: "text/html", Lang: "en", Variant1: "", Variant2: "", LayoutMustMatch: false, IsPlainText: false}, TemplateDescriptor{Kind: "", LayoutFromTemplate: "", OutputFormat: "404", MediaType: "text/html", Lang: "en", Variant1: "", Variant2: "", LayoutFromUserMustMatch: false, IsPlainText: false},
TemplateDescriptor{Kind: "", Layout: "", OutputFormat: "rss", MediaType: "application/rss+xml", Lang: "", Variant1: "", Variant2: "", LayoutMustMatch: false, IsPlainText: false}, TemplateDescriptor{Kind: "", LayoutFromTemplate: "", OutputFormat: "rss", MediaType: "application/rss+xml", Lang: "", Variant1: "", Variant2: "", LayoutFromUserMustMatch: false, IsPlainText: false},
}, },
{ {
TemplateDescriptor{Kind: "page", Layout: "single", OutputFormat: "html", MediaType: "text/html", Lang: "en", Variant1: "", Variant2: "", LayoutMustMatch: false, IsPlainText: false}, TemplateDescriptor{Kind: "page", LayoutFromTemplate: "single", OutputFormat: "html", MediaType: "text/html", Lang: "en", Variant1: "", Variant2: "", LayoutFromUserMustMatch: false, IsPlainText: false},
TemplateDescriptor{Kind: "", Layout: "list", OutputFormat: "", MediaType: "application/rss+xml", Lang: "", Variant1: "", Variant2: "", LayoutMustMatch: false, IsPlainText: false}, TemplateDescriptor{Kind: "", LayoutFromTemplate: "list", OutputFormat: "", MediaType: "application/rss+xml", Lang: "", Variant1: "", Variant2: "", LayoutFromUserMustMatch: false, IsPlainText: false},
}, },
{ {
TemplateDescriptor{Kind: "page", Layout: "single", OutputFormat: "html", MediaType: "text/html", Lang: "en", Variant1: "", Variant2: "", LayoutMustMatch: false, IsPlainText: false}, TemplateDescriptor{Kind: "page", LayoutFromTemplate: "single", OutputFormat: "html", MediaType: "text/html", Lang: "en", Variant1: "", Variant2: "", LayoutFromUserMustMatch: false, IsPlainText: false},
TemplateDescriptor{Kind: "", Layout: "", OutputFormat: "alias", MediaType: "text/html", Lang: "", Variant1: "", Variant2: "", LayoutMustMatch: false, IsPlainText: false}, TemplateDescriptor{Kind: "", LayoutFromTemplate: "", OutputFormat: "alias", MediaType: "text/html", Lang: "", Variant1: "", Variant2: "", LayoutFromUserMustMatch: false, IsPlainText: false},
}, },
{ {
TemplateDescriptor{Kind: "page", Layout: "single", OutputFormat: "rss", MediaType: "application/rss+xml", Lang: "en", Variant1: "", Variant2: "", LayoutMustMatch: false, IsPlainText: false}, TemplateDescriptor{Kind: "page", LayoutFromTemplate: "single", OutputFormat: "rss", MediaType: "application/rss+xml", Lang: "en", Variant1: "", Variant2: "", LayoutFromUserMustMatch: false, IsPlainText: false},
TemplateDescriptor{Kind: "", Layout: "single", OutputFormat: "rss", MediaType: "application/rss+xml", Lang: "nn", Variant1: "", Variant2: "", LayoutMustMatch: false, IsPlainText: false}, TemplateDescriptor{Kind: "", LayoutFromTemplate: "single", OutputFormat: "rss", MediaType: "application/rss+xml", Lang: "nn", Variant1: "", Variant2: "", LayoutFromUserMustMatch: false, IsPlainText: false},
}, },
} }

View file

@ -378,11 +378,11 @@ func (q *TemplateQuery) init() {
} else if kinds.GetKindMain(q.Desc.Kind) == "" { } else if kinds.GetKindMain(q.Desc.Kind) == "" {
q.Desc.Kind = "" q.Desc.Kind = ""
} }
if q.Desc.Layout == "" && q.Desc.Kind != "" { if q.Desc.LayoutFromTemplate == "" && q.Desc.Kind != "" {
if q.Desc.Kind == kinds.KindPage { if q.Desc.Kind == kinds.KindPage {
q.Desc.Layout = layoutSingle q.Desc.LayoutFromTemplate = layoutSingle
} else { } else {
q.Desc.Layout = layoutList q.Desc.LayoutFromTemplate = layoutList
} }
} }
@ -447,7 +447,7 @@ func (s *TemplateStore) FindAllBaseTemplateCandidates(overlayKey string, desc Te
continue continue
} }
if vv.D.isKindInLayout(desc.Layout) && s.dh.compareDescriptors(CategoryBaseof, false, descBaseof, vv.D).w1 > 0 { if vv.D.isKindInLayout(desc.LayoutFromTemplate) && s.dh.compareDescriptors(CategoryBaseof, false, descBaseof, vv.D).w1 > 0 {
result = append(result, keyTemplateInfo{Key: k, Info: vv}) result = append(result, keyTemplateInfo{Key: k, Info: vv})
} }
} }
@ -549,7 +549,7 @@ func (s *TemplateStore) LookupPartial(pth string) *TemplInfo {
ti, _ := s.cacheLookupPartials.GetOrCreate(pth, func() (*TemplInfo, error) { ti, _ := s.cacheLookupPartials.GetOrCreate(pth, func() (*TemplInfo, error) {
d := s.templateDescriptorFromPath(pth) d := s.templateDescriptorFromPath(pth)
desc := d.Desc desc := d.Desc
if desc.Layout != "" { if desc.LayoutFromTemplate != "" {
panic("shortcode template descriptor must not have a layout") panic("shortcode template descriptor must not have a layout")
} }
best := s.getBest() best := s.getBest()
@ -610,7 +610,7 @@ func (s *TemplateStore) PrintDebug(prefix string, category Category, w io.Writer
return return
} }
s := strings.ReplaceAll(strings.TrimSpace(vv.content), "\n", " ") s := strings.ReplaceAll(strings.TrimSpace(vv.content), "\n", " ")
ts := fmt.Sprintf("kind: %q layout: %q content: %.30s", vv.D.Kind, vv.D.Layout, s) ts := fmt.Sprintf("kind: %q layout: %q content: %.30s", vv.D.Kind, vv.D.LayoutFromTemplate, s)
fmt.Fprintf(w, "%s%s %s\n", strings.Repeat(" ", level), key, ts) fmt.Fprintf(w, "%s%s %s\n", strings.Repeat(" ", level), key, ts)
} }
s.treeMain.WalkPrefix(prefix, func(key string, v map[nodeKey]*TemplInfo) (bool, error) { s.treeMain.WalkPrefix(prefix, func(key string, v map[nodeKey]*TemplInfo) (bool, error) {
@ -1573,12 +1573,12 @@ func (s *TemplateStore) toKeyCategoryAndDescriptor(p *paths.Path) (string, strin
} }
d := TemplateDescriptor{ d := TemplateDescriptor{
Lang: p.Lang(), Lang: p.Lang(),
OutputFormat: p.OutputFormat(), OutputFormat: p.OutputFormat(),
MediaType: mediaType.Type, MediaType: mediaType.Type,
Kind: p.Kind(), Kind: p.Kind(),
Layout: layout, LayoutFromTemplate: layout,
IsPlainText: outputFormat.IsPlainText, IsPlainText: outputFormat.IsPlainText,
} }
d.normalizeFromFile() d.normalizeFromFile()
@ -1611,7 +1611,7 @@ func (s *TemplateStore) toKeyCategoryAndDescriptor(p *paths.Path) (string, strin
} }
if category == CategoryPartial { if category == CategoryPartial {
d.Layout = "" d.LayoutFromTemplate = ""
k1 = p.PathNoIdentifier() k1 = p.PathNoIdentifier()
} }
@ -1626,15 +1626,15 @@ func (s *TemplateStore) toKeyCategoryAndDescriptor(p *paths.Path) (string, strin
} }
// Legacy layout for home page. // Legacy layout for home page.
if d.Layout == "index" { if d.LayoutFromTemplate == "index" {
if d.Kind == "" { if d.Kind == "" {
d.Kind = kinds.KindHome d.Kind = kinds.KindHome
} }
d.Layout = "" d.LayoutFromTemplate = ""
} }
if d.Layout == d.Kind { if d.LayoutFromTemplate == d.Kind {
d.Layout = "" d.LayoutFromTemplate = ""
} }
k1 = strings.TrimPrefix(k1, "/_default") k1 = strings.TrimPrefix(k1, "/_default")
@ -1645,7 +1645,7 @@ func (s *TemplateStore) toKeyCategoryAndDescriptor(p *paths.Path) (string, strin
if category == CategoryMarkup { if category == CategoryMarkup {
// We store all template nodes for a given directory on the same level. // We store all template nodes for a given directory on the same level.
k1 = strings.TrimSuffix(k1, "/_markup") k1 = strings.TrimSuffix(k1, "/_markup")
parts := strings.Split(d.Layout, "-") parts := strings.Split(d.LayoutFromTemplate, "-")
if len(parts) < 2 { if len(parts) < 2 {
return "", "", 0, TemplateDescriptor{}, fmt.Errorf("unrecognized render hook template") return "", "", 0, TemplateDescriptor{}, fmt.Errorf("unrecognized render hook template")
} }
@ -1654,7 +1654,7 @@ func (s *TemplateStore) toKeyCategoryAndDescriptor(p *paths.Path) (string, strin
if len(parts) > 2 { if len(parts) > 2 {
d.Variant2 = parts[2] d.Variant2 = parts[2]
} }
d.Layout = "" // This allows using page layout as part of the key for lookups. d.LayoutFromTemplate = "" // This allows using page layout as part of the key for lookups.
} }
return k1, k2, category, d, nil return k1, k2, category, d, nil
@ -1868,8 +1868,8 @@ func (best *bestMatch) isBetter(w weight, ti *TemplInfo) bool {
return true return true
} }
if ti.D.Layout != "" && best.desc.Layout != "" { if ti.D.LayoutFromTemplate != "" && best.desc.LayoutFromTemplate != "" {
return ti.D.Layout != layoutAll return ti.D.LayoutFromTemplate != layoutAll
} }
return w.distance < best.w.distance || ti.PathInfo.Path() < best.templ.PathInfo.Path() return w.distance < best.w.distance || ti.PathInfo.Path() < best.templ.PathInfo.Path()
@ -1920,17 +1920,6 @@ type weight struct {
distance int distance int
} }
func (w weight) isEqualWeights(other weight) bool {
return w.w1 == other.w1 && w.w2 == other.w2 && w.w3 == other.w3
}
func isLayoutCustom(s string) bool {
if s == "" || isLayoutStandard(s) {
return false
}
return true
}
func isLayoutStandard(s string) bool { func isLayoutStandard(s string) bool {
switch s { switch s {
case layoutAll, layoutList, layoutSingle: case layoutAll, layoutList, layoutSingle:
@ -1940,6 +1929,10 @@ func isLayoutStandard(s string) bool {
} }
} }
func (w weight) isEqualWeights(other weight) bool {
return w.w1 == other.w1 && w.w2 == other.w2 && w.w3 == other.w3
}
func configureSiteStorage(opts SiteOptions, watching bool) *storeSite { func configureSiteStorage(opts SiteOptions, watching bool) *storeSite {
funcsv := make(map[string]reflect.Value) funcsv := make(map[string]reflect.Value)

View file

@ -510,7 +510,7 @@ baseof: {{ block "main" . }}{{ end }}
q := tplimpl.TemplateQuery{ q := tplimpl.TemplateQuery{
Path: "/baz", Path: "/baz",
Category: tplimpl.CategoryLayout, 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++ { for i := 0; i < b.N; i++ {
store.LookupPagesLayout(q) store.LookupPagesLayout(q)
@ -521,7 +521,7 @@ baseof: {{ block "main" . }}{{ end }}
q := tplimpl.TemplateQuery{ q := tplimpl.TemplateQuery{
Path: "/foo/bar", Path: "/foo/bar",
Category: tplimpl.CategoryLayout, 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++ { for i := 0; i < b.N; i++ {
store.LookupPagesLayout(q) store.LookupPagesLayout(q)
@ -648,9 +648,6 @@ layout: mylayout
b := hugolib.Test(t, files, hugolib.TestOptWarn()) b := hugolib.Test(t, files, hugolib.TestOptWarn())
// s := b.H.Sites[0].TemplateStore
// s.PrintDebug("", tplimpl.CategoryLayout, os.Stdout)
b.AssertLogContains("! WARN") b.AssertLogContains("! WARN")
// Single pages. // 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) { func TestSkipDotFiles(t *testing.T) {
t.Parallel() t.Parallel()