tpl: Skip dot and temp files inside /layouts

Fixes #13579
This commit is contained in:
Bjørn Erik Pedersen 2025-04-10 17:55:46 +02:00
parent 648204b3f1
commit 3b9f2a7ded
2 changed files with 29 additions and 1 deletions

View file

@ -1118,15 +1118,20 @@ func (s *TemplateStore) insertTemplates(include func(fi hugofs.FileMetaInfo) boo
legacyOrdinalMappings := map[legacyTargetPathIdentifiers]legacyOrdinalMappingFi{} legacyOrdinalMappings := map[legacyTargetPathIdentifiers]legacyOrdinalMappingFi{}
walker := func(pth string, fi hugofs.FileMetaInfo) error { walker := func(pth string, fi hugofs.FileMetaInfo) error {
piOrig := fi.Meta().PathInfo
if fi.IsDir() { if fi.IsDir() {
return nil return nil
} }
if isDotFile(pth) || isBackupFile(pth) {
return nil
}
if !include(fi) { if !include(fi) {
return nil return nil
} }
piOrig := fi.Meta().PathInfo
// Convert any legacy value to new format. // Convert any legacy value to new format.
fromLegacyPath := func(pi *paths.Path) *paths.Path { fromLegacyPath := func(pi *paths.Path) *paths.Path {
p := pi.Path() p := pi.Path()
@ -1922,3 +1927,11 @@ func configureSiteStorage(opts SiteOptions, watching bool) *storeSite {
return s return s
} }
func isBackupFile(path string) bool {
return path[len(path)-1] == '~'
}
func isDotFile(path string) bool {
return filepath.Base(path)[0] == '.'
}

View file

@ -973,3 +973,18 @@ s2.
} }
}) })
} }
func TestSkipDotFiles(t *testing.T) {
t.Parallel()
files := `
-- hugo.toml --
-- layouts/all.html --
All.
-- layouts/.DS_Store --
{{ foo }}
`
// Just make sure it doesn't fail.
hugolib.Test(t, files)
}