From 3b9f2a7ded7a7b011223b4420e1c8994eeb00986 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 10 Apr 2025 17:55:46 +0200 Subject: [PATCH] tpl: Skip dot and temp files inside /layouts Fixes #13579 --- tpl/tplimpl/templatestore.go | 15 ++++++++++++++- tpl/tplimpl/templatestore_integration_test.go | 15 +++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/tpl/tplimpl/templatestore.go b/tpl/tplimpl/templatestore.go index df4ea649f..eee962053 100644 --- a/tpl/tplimpl/templatestore.go +++ b/tpl/tplimpl/templatestore.go @@ -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] == '.' +} diff --git a/tpl/tplimpl/templatestore_integration_test.go b/tpl/tplimpl/templatestore_integration_test.go index 8e62df1d0..4f76626ad 100644 --- a/tpl/tplimpl/templatestore_integration_test.go +++ b/tpl/tplimpl/templatestore_integration_test.go @@ -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) +}