Skip to content

Commit d4c0e44

Browse files
committed
Fix error with _content.gotmpl file with index.md siblings
Regression introduced in Hugo 0.153.0. Note that this is a very uncommon setup, but it worked before. Fixes gohugoio#14299
1 parent 418156e commit d4c0e44

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

‎hugofs/component_fs.go‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,13 +206,15 @@ func (f *componentFsDir) ReadDirWithContext(ctx context.Context, count int) ([]i
206206
}
207207
pi := fi.(FileMetaInfo).Meta().PathInfo
208208

209-
// Everything below a leaf bundle is a resource.
210-
isResource := isInLeafBundle && pi.Type() > paths.TypeFile
211-
// Every sibling of a leaf bundle is a resource.
212-
isResource = isResource || (isCurrentLeafBundle && !pi.IsLeafBundle())
213-
214-
if isResource {
215-
paths.ModifyPathBundleTypeResource(pi)
209+
if pi.Type() != paths.TypeContentData {
210+
// Everything below a leaf bundle is a resource.
211+
isResource := isInLeafBundle && pi.Type() > paths.TypeFile
212+
// Every sibling of a leaf bundle is a resource.
213+
isResource = isResource || (isCurrentLeafBundle && !pi.IsLeafBundle())
214+
215+
if isResource {
216+
paths.ModifyPathBundleTypeResource(pi)
217+
}
216218
}
217219
}
218220
}

‎hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,3 +873,23 @@ baseURL = "https://example.com"
873873

874874
b.AssertFileContent("public/index.html", "home: My Home!|")
875875
}
876+
877+
func TestPagesFromGoTmplIssue14299(t *testing.T) {
878+
t.Parallel()
879+
880+
files := `
881+
-- hugo.toml --
882+
disableKinds = ["taxonomy", "term", "rss", "sitemap"]
883+
baseURL = "https://example.com"
884+
-- layouts/all.html --
885+
{{ .Kind }}: {{ .Title }}|
886+
-- content/_content.gotmpl --
887+
{{ $a := "foo" }}
888+
-- content/_index.md --
889+
-- content/bar/_content.gotmpl --
890+
{{ $a := "bar" }}
891+
-- content/bar/index.md --
892+
`
893+
// _content.gotmpl which was siblings of index.md (leaf bundles) was mistakingly classified as a content resource.
894+
hugolib.Test(t, files)
895+
}

0 commit comments

Comments
 (0)