]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
hugolib: Honor implicit "page" type during template selection
authorJoe Mooring <joe.mooring@veriphor.com>
Wed, 2 Jul 2025 10:05:40 +0000 (03:05 -0700)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 2 Jul 2025 11:43:40 +0000 (13:43 +0200)
Closes #13826

common/paths/pathparser.go
hugolib/page.go
hugolib/page_test.go

index 1cae710e8f1fe9522521f01724ed0f3eb4fae3d1..8b9259bf73dc38509b0abe17021b3375dd20b7c7 100644 (file)
@@ -640,7 +640,7 @@ func (p *Path) Base() string {
 // For pages with Type set, we treat that as the section.
 func (p *Path) BaseReTyped(typ string) (d string) {
        base := p.Base()
-       if typ == "" || p.Section() == typ {
+       if p.Section() == typ {
                return base
        }
        d = "/" + typ
index bb3835c1e143d91a119be812af4bbc00588b0eb4..dc0d9f4bce1e82d9158dff8d585b637593ab832c 100644 (file)
@@ -479,7 +479,7 @@ func (ps *pageState) initCommonProviders(pp pagePaths) error {
 func (po *pageOutput) GetInternalTemplateBasePathAndDescriptor() (string, tplimpl.TemplateDescriptor) {
        p := po.p
        f := po.f
-       base := p.PathInfo().BaseReTyped(p.m.pageConfig.Type)
+       base := p.PathInfo().BaseReTyped(p.m.Type())
        return base, tplimpl.TemplateDescriptor{
                Kind:           p.Kind(),
                Lang:           p.Language().Lang,
index 1da67e58f56e11274336b3bbde2d3a15b1d4389c..d4185531be701d0ecfd8a5630aa36cb1c09b7e00 100644 (file)
@@ -2000,3 +2000,61 @@ title: home en
        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.")
        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.")
 }
+
+// Issue 13826
+func TestTemplateSelectionIssue13826(t *testing.T) {
+       t.Parallel()
+
+       files := `
+-- hugo.toml --
+disableKinds = ['home','rss','section','sitemap','taxonomy','term']
+-- content/p1.md --
+---
+title: p1 (type implicitly set to page)
+---
+-- content/p2.md --
+---
+title: p2 (type explicitly set to page)
+type: page
+---
+-- content/p3.md --
+---
+title: p3 (type explicitly set to foo)
+type: foo
+---
+-- content/foo/p4.md --
+---
+title: p4 (type implicitly set to foo)
+---
+-- content/bar/p5.md --
+---
+title: p5 (type explicitly set to foo)
+type: foo
+---
+-- layouts/page/page.html --
+layouts/page/page.html
+-- layouts/foo/page.html --
+layouts/foo/page.html
+-- layouts/page.html --
+layouts/page.html
+`
+
+       b := Test(t, files)
+
+       b.AssertFileContent("public/p1/index.html", "layouts/page/page.html")
+       b.AssertFileContent("public/p2/index.html", "layouts/page/page.html")
+       b.AssertFileContent("public/p3/index.html", "layouts/foo/page.html")
+       b.AssertFileContent("public/foo/p4/index.html", "layouts/foo/page.html")
+       b.AssertFileContent("public/bar/p5/index.html", "layouts/foo/page.html")
+
+       files = strings.ReplaceAll(files, "-- layouts/page/page.html --", "-- delete-me-1.txt --")
+       files = strings.ReplaceAll(files, "-- layouts/foo/page.html --", "-- delete-me-2.txt --")
+
+       b = Test(t, files)
+
+       b.AssertFileContent("public/p1/index.html", "layouts/page.html")
+       b.AssertFileContent("public/p2/index.html", "layouts/page.html")
+       b.AssertFileContent("public/p3/index.html", "layouts/page.html")
+       b.AssertFileContent("public/foo/p4/index.html", "layouts/page.html")
+       b.AssertFileContent("public/bar/p5/index.html", "layouts/page.html")
+}