Skip to content

Commit cfc8d31

Browse files
jmooringbep
authored andcommitted
hugolib: Honor implicit "page" type during template selection
Closes #13826
1 parent dd6e2c8 commit cfc8d31

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

common/paths/pathparser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ func (p *Path) Base() string {
640640
// For pages with Type set, we treat that as the section.
641641
func (p *Path) BaseReTyped(typ string) (d string) {
642642
base := p.Base()
643-
if typ == "" || p.Section() == typ {
643+
if p.Section() == typ {
644644
return base
645645
}
646646
d = "/" + typ

hugolib/page.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ func (ps *pageState) initCommonProviders(pp pagePaths) error {
479479
func (po *pageOutput) GetInternalTemplateBasePathAndDescriptor() (string, tplimpl.TemplateDescriptor) {
480480
p := po.p
481481
f := po.f
482-
base := p.PathInfo().BaseReTyped(p.m.pageConfig.Type)
482+
base := p.PathInfo().BaseReTyped(p.m.Type())
483483
return base, tplimpl.TemplateDescriptor{
484484
Kind: p.Kind(),
485485
Lang: p.Language().Lang,

hugolib/page_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,3 +2000,61 @@ title: home en
20002000
b.AssertLogContains("Using index.de.md in your content's root directory is usually incorrect for your home page. You should use _index.de.md instead.")
20012001
b.AssertLogContains("Using index.en.org in your content's root directory is usually incorrect for your home page. You should use _index.en.org instead.")
20022002
}
2003+
2004+
// Issue 13826
2005+
func TestTemplateSelectionIssue13826(t *testing.T) {
2006+
t.Parallel()
2007+
2008+
files := `
2009+
-- hugo.toml --
2010+
disableKinds = ['home','rss','section','sitemap','taxonomy','term']
2011+
-- content/p1.md --
2012+
---
2013+
title: p1 (type implicitly set to page)
2014+
---
2015+
-- content/p2.md --
2016+
---
2017+
title: p2 (type explicitly set to page)
2018+
type: page
2019+
---
2020+
-- content/p3.md --
2021+
---
2022+
title: p3 (type explicitly set to foo)
2023+
type: foo
2024+
---
2025+
-- content/foo/p4.md --
2026+
---
2027+
title: p4 (type implicitly set to foo)
2028+
---
2029+
-- content/bar/p5.md --
2030+
---
2031+
title: p5 (type explicitly set to foo)
2032+
type: foo
2033+
---
2034+
-- layouts/page/page.html --
2035+
layouts/page/page.html
2036+
-- layouts/foo/page.html --
2037+
layouts/foo/page.html
2038+
-- layouts/page.html --
2039+
layouts/page.html
2040+
`
2041+
2042+
b := Test(t, files)
2043+
2044+
b.AssertFileContent("public/p1/index.html", "layouts/page/page.html")
2045+
b.AssertFileContent("public/p2/index.html", "layouts/page/page.html")
2046+
b.AssertFileContent("public/p3/index.html", "layouts/foo/page.html")
2047+
b.AssertFileContent("public/foo/p4/index.html", "layouts/foo/page.html")
2048+
b.AssertFileContent("public/bar/p5/index.html", "layouts/foo/page.html")
2049+
2050+
files = strings.ReplaceAll(files, "-- layouts/page/page.html --", "-- delete-me-1.txt --")
2051+
files = strings.ReplaceAll(files, "-- layouts/foo/page.html --", "-- delete-me-2.txt --")
2052+
2053+
b = Test(t, files)
2054+
2055+
b.AssertFileContent("public/p1/index.html", "layouts/page.html")
2056+
b.AssertFileContent("public/p2/index.html", "layouts/page.html")
2057+
b.AssertFileContent("public/p3/index.html", "layouts/page.html")
2058+
b.AssertFileContent("public/foo/p4/index.html", "layouts/page.html")
2059+
b.AssertFileContent("public/bar/p5/index.html", "layouts/page.html")
2060+
}

0 commit comments

Comments
 (0)