Skip to content

Commit 3b9f2a7

Browse files
committed
tpl: Skip dot and temp files inside /layouts
Fixes #13579
1 parent 648204b commit 3b9f2a7

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

tpl/tplimpl/templatestore.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -1118,15 +1118,20 @@ func (s *TemplateStore) insertTemplates(include func(fi hugofs.FileMetaInfo) boo
11181118
legacyOrdinalMappings := map[legacyTargetPathIdentifiers]legacyOrdinalMappingFi{}
11191119

11201120
walker := func(pth string, fi hugofs.FileMetaInfo) error {
1121-
piOrig := fi.Meta().PathInfo
11221121
if fi.IsDir() {
11231122
return nil
11241123
}
11251124

1125+
if isDotFile(pth) || isBackupFile(pth) {
1126+
return nil
1127+
}
1128+
11261129
if !include(fi) {
11271130
return nil
11281131
}
11291132

1133+
piOrig := fi.Meta().PathInfo
1134+
11301135
// Convert any legacy value to new format.
11311136
fromLegacyPath := func(pi *paths.Path) *paths.Path {
11321137
p := pi.Path()
@@ -1922,3 +1927,11 @@ func configureSiteStorage(opts SiteOptions, watching bool) *storeSite {
19221927

19231928
return s
19241929
}
1930+
1931+
func isBackupFile(path string) bool {
1932+
return path[len(path)-1] == '~'
1933+
}
1934+
1935+
func isDotFile(path string) bool {
1936+
return filepath.Base(path)[0] == '.'
1937+
}

tpl/tplimpl/templatestore_integration_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -973,3 +973,18 @@ s2.
973973
}
974974
})
975975
}
976+
977+
func TestSkipDotFiles(t *testing.T) {
978+
t.Parallel()
979+
980+
files := `
981+
-- hugo.toml --
982+
-- layouts/all.html --
983+
All.
984+
-- layouts/.DS_Store --
985+
{{ foo }}
986+
`
987+
988+
// Just make sure it doesn't fail.
989+
hugolib.Test(t, files)
990+
}

0 commit comments

Comments
 (0)