]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Fix error with _content.gotmpl file with index.md siblings
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 25 Dec 2025 11:03:55 +0000 (12:03 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 25 Dec 2025 13:22:14 +0000 (14:22 +0100)
Regression introduced in Hugo 0.153.0.

Note that this is a very uncommon setup, but it worked before.

Fixes #14299

hugofs/component_fs.go
hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go

index b4aaa2acdf88796e2ce45a3219f2d32b7dea8e38..5b9e69d64f6fe6d74267561e900b11a968aa08f0 100644 (file)
@@ -206,13 +206,15 @@ func (f *componentFsDir) ReadDirWithContext(ctx context.Context, count int) ([]i
                                }
                                pi := fi.(FileMetaInfo).Meta().PathInfo
 
-                               // Everything below a leaf bundle is a resource.
-                               isResource := isInLeafBundle && pi.Type() > paths.TypeFile
-                               // Every sibling of a leaf bundle is a resource.
-                               isResource = isResource || (isCurrentLeafBundle && !pi.IsLeafBundle())
-
-                               if isResource {
-                                       paths.ModifyPathBundleTypeResource(pi)
+                               if pi.Type() != paths.TypeContentData {
+                                       // Everything below a leaf bundle is a resource.
+                                       isResource := isInLeafBundle && pi.Type() > paths.TypeFile
+                                       // Every sibling of a leaf bundle is a resource.
+                                       isResource = isResource || (isCurrentLeafBundle && !pi.IsLeafBundle())
+
+                                       if isResource {
+                                               paths.ModifyPathBundleTypeResource(pi)
+                                       }
                                }
                        }
                }
index 6c8c376b0477ee91c9ef04c430607d321d39ed9d..30b6cab33725021a1f744187f107039167f3717c 100644 (file)
@@ -873,3 +873,23 @@ baseURL = "https://example.com"
 
        b.AssertFileContent("public/index.html", "home: My Home!|")
 }
+
+func TestPagesFromGoTmplIssue14299(t *testing.T) {
+       t.Parallel()
+
+       files := `
+-- hugo.toml --
+disableKinds = ["taxonomy", "term", "rss", "sitemap"]
+baseURL = "https://example.com"
+-- layouts/all.html --
+{{ .Kind }}: {{ .Title }}|
+-- content/_content.gotmpl --
+{{ $a := "foo" }}
+-- content/_index.md --
+-- content/bar/_content.gotmpl --
+{{ $a := "bar" }}
+-- content/bar/index.md --
+`
+       // _content.gotmpl which was siblings of index.md (leaf bundles) was mistakingly classified as a content resource.
+       hugolib.Test(t, files)
+}