]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
tpl: Skip dot and temp files inside /layouts
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 10 Apr 2025 15:55:46 +0000 (17:55 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 10 Apr 2025 16:41:01 +0000 (18:41 +0200)
Fixes #13579

tpl/tplimpl/templatestore.go
tpl/tplimpl/templatestore_integration_test.go

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