]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
tpl: Fix when layout specified in front matter and no match is found
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 20 Apr 2025 08:59:40 +0000 (10:59 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Sun, 20 Apr 2025 10:55:18 +0000 (12:55 +0200)
Fixes #13628

tpl/tplimpl/templatedescriptor.go
tpl/tplimpl/templatestore_integration_test.go

index 8e4390faebdf2f6bce1bb7fd2c5541166f548ef4..ca73c9f783299512f629dceceb2c170589d60618 100644 (file)
@@ -177,7 +177,7 @@ func (this TemplateDescriptor) doCompare(category Category, isEmbedded bool, oth
                w.w2 = weight2Group1
        }
 
-       if this.LayoutFromUser == "" && other.LayoutFromTemplate != "" && (other.LayoutFromTemplate == this.LayoutFromTemplate || other.LayoutFromTemplate == layoutAll) {
+       if other.LayoutFromTemplate != "" && (other.LayoutFromTemplate == this.LayoutFromTemplate || other.LayoutFromTemplate == layoutAll) {
                w.w1 += weightLayoutStandard
                w.w2 = weight2Group1
 
index 32e1248fe279d5eaf42d0f4476d6b3f83d9483cf..e59dad33a52adbdb91ba67c2ce0ceca058366847 100644 (file)
@@ -1204,3 +1204,28 @@ layouts/_partials/comment.ru.xml
        b.AssertFileContent("public/ru/index.html", "layouts/_partials/comment.ru.html") // fail
        b.AssertFileContent("public/ru/index.xml", "layouts/_partials/comment.ru.xml")   // fail
 }
+
+func TestLayoutIssue13628(t *testing.T) {
+       t.Parallel()
+
+       files := `
+-- hugo.toml --
+disableKinds = ['home','rss','sitemap','taxonomy','term']
+-- content/p1.md --
+---
+title: p1
+layout: foo
+---
+-- layouts/single.html --
+layouts/single.html
+-- layouts/list.html --
+layouts/list.html
+`
+
+       for range 5 {
+
+               b := hugolib.Test(t, files)
+
+               b.AssertFileContent("public/p1/index.html", "layouts/single.html")
+       }
+}