Skip to content

Commit 9df7b29

Browse files
committed
Filter dot files etc. in i18n
Closes gohugoio#11993
1 parent c37bf19 commit 9df7b29

File tree

5 files changed

+38
-14
lines changed

5 files changed

+38
-14
lines changed

hugofs/walk.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ type WalkwayConfig struct {
5353
Logger loggers.Logger
5454

5555
// One or both of these may be pre-set.
56-
Info FileMetaInfo // The start info.
57-
DirEntries []FileMetaInfo // The start info's dir entries.
56+
Info FileMetaInfo // The start info.
57+
DirEntries []FileMetaInfo // The start info's dir entries.
58+
IgnoreFile func(filename string) bool // Optional
5859

5960
// Will be called in order.
6061
HookPre WalkHook // Optional.
@@ -172,6 +173,17 @@ func (w *Walkway) walk(path string, info FileMetaInfo, dirEntries []FileMetaInfo
172173

173174
}
174175

176+
if w.cfg.IgnoreFile != nil {
177+
n := 0
178+
for _, fi := range dirEntries {
179+
if !w.cfg.IgnoreFile(fi.Meta().Filename) {
180+
dirEntries[n] = fi
181+
n++
182+
}
183+
}
184+
dirEntries = dirEntries[:n]
185+
}
186+
175187
if w.cfg.HookPre != nil {
176188
var err error
177189
dirEntries, err = w.cfg.HookPre(info, path, dirEntries)

hugolib/hugo_sites.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,8 @@ func (h *HugoSites) loadData() error {
473473
h.data = make(map[string]any)
474474
w := hugofs.NewWalkway(
475475
hugofs.WalkwayConfig{
476-
Fs: h.PathSpec.BaseFs.Data.Fs,
476+
Fs: h.PathSpec.BaseFs.Data.Fs,
477+
IgnoreFile: h.SourceSpec.IgnoreFile,
477478
WalkFn: func(path string, fi hugofs.FileMetaInfo) error {
478479
if fi.IsDir() {
479480
return nil

hugolib/language_test.go

+11
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,14 @@ FormatNumberCustom: 12,345.68
135135
NumFmt: -98,765.43
136136
`)
137137
}
138+
139+
// Issue 11993.
140+
func TestI18nDotFile(t *testing.T) {
141+
files := `
142+
-- hugo.toml --{}
143+
baseURL = "https://example.com"
144+
-- i18n/.keep --
145+
-- data/.keep --
146+
`
147+
Test(t, files)
148+
}

hugolib/pages_capture.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,6 @@ func (c *pagesCollector) collectDir(dirPath *paths.Path, isDir bool, inFilter fu
249249

250250
func (c *pagesCollector) collectDirDir(path string, root hugofs.FileMetaInfo, inFilter func(fim hugofs.FileMetaInfo) bool) error {
251251
filter := func(fim hugofs.FileMetaInfo) bool {
252-
if c.sp.IgnoreFile(fim.Meta().Filename) {
253-
return false
254-
}
255252
if inFilter != nil {
256253
return inFilter(fim)
257254
}
@@ -330,13 +327,14 @@ func (c *pagesCollector) collectDirDir(path string, root hugofs.FileMetaInfo, in
330327

331328
w := hugofs.NewWalkway(
332329
hugofs.WalkwayConfig{
333-
Logger: c.logger,
334-
Root: path,
335-
Info: root,
336-
Fs: c.fs,
337-
HookPre: preHook,
338-
HookPost: postHook,
339-
WalkFn: wfn,
330+
Logger: c.logger,
331+
Root: path,
332+
Info: root,
333+
Fs: c.fs,
334+
IgnoreFile: c.h.SourceSpec.IgnoreFile,
335+
HookPre: preHook,
336+
HookPost: postHook,
337+
WalkFn: wfn,
340338
})
341339

342340
return w.Walk()
@@ -371,6 +369,7 @@ func (c *pagesCollector) handleBundleLeaf(dir, bundle hugofs.FileMetaInfo, inPat
371369
Logger: c.logger,
372370
Info: dir,
373371
DirEntries: readdir,
372+
IgnoreFile: c.h.SourceSpec.IgnoreFile,
374373
WalkFn: walk,
375374
})
376375

langs/i18n/translationProvider.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ func (tp *TranslationProvider) NewResource(dst *deps.Deps) error {
5959

6060
w := hugofs.NewWalkway(
6161
hugofs.WalkwayConfig{
62-
Fs: dst.BaseFs.I18n.Fs,
62+
Fs: dst.BaseFs.I18n.Fs,
63+
IgnoreFile: dst.SourceSpec.IgnoreFile,
6364
WalkFn: func(path string, info hugofs.FileMetaInfo) error {
6465
if info.IsDir() {
6566
return nil

0 commit comments

Comments
 (0)