]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
Filter dot files etc. in i18n
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 5 Feb 2024 13:54:02 +0000 (14:54 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 5 Feb 2024 13:54:02 +0000 (14:54 +0100)
Closes #11993

hugofs/walk.go
hugolib/hugo_sites.go
hugolib/language_test.go
hugolib/pages_capture.go
langs/i18n/translationProvider.go

index 18667a5fce03c76f455fbc1e1e5ac53667e2709f..391f70a65884d51d20ceae5fb471a5fc821e0bef 100644 (file)
@@ -53,8 +53,9 @@ type WalkwayConfig struct {
        Logger loggers.Logger
 
        // One or both of these may be pre-set.
-       Info       FileMetaInfo   // The start info.
-       DirEntries []FileMetaInfo // The start info's dir entries.
+       Info       FileMetaInfo               // The start info.
+       DirEntries []FileMetaInfo             // The start info's dir entries.
+       IgnoreFile func(filename string) bool // Optional
 
        // Will be called in order.
        HookPre  WalkHook // Optional.
@@ -172,6 +173,17 @@ func (w *Walkway) walk(path string, info FileMetaInfo, dirEntries []FileMetaInfo
 
        }
 
+       if w.cfg.IgnoreFile != nil {
+               n := 0
+               for _, fi := range dirEntries {
+                       if !w.cfg.IgnoreFile(fi.Meta().Filename) {
+                               dirEntries[n] = fi
+                               n++
+                       }
+               }
+               dirEntries = dirEntries[:n]
+       }
+
        if w.cfg.HookPre != nil {
                var err error
                dirEntries, err = w.cfg.HookPre(info, path, dirEntries)
index 24ff1077f8bf1fb9e01ce9ae63c537480851b75d..99dc88b10a1f78d238c7de174a131cacfab88d2a 100644 (file)
@@ -473,7 +473,8 @@ func (h *HugoSites) loadData() error {
        h.data = make(map[string]any)
        w := hugofs.NewWalkway(
                hugofs.WalkwayConfig{
-                       Fs: h.PathSpec.BaseFs.Data.Fs,
+                       Fs:         h.PathSpec.BaseFs.Data.Fs,
+                       IgnoreFile: h.SourceSpec.IgnoreFile,
                        WalkFn: func(path string, fi hugofs.FileMetaInfo) error {
                                if fi.IsDir() {
                                        return nil
index c9368770e4559b4d789ca241f2e5e58629d38218..582d3985fdb7c3beed3b1370f95fa931611ddf1a 100644 (file)
@@ -135,3 +135,14 @@ FormatNumberCustom: 12,345.68
 NumFmt: -98,765.43
 `)
 }
+
+// Issue 11993.
+func TestI18nDotFile(t *testing.T) {
+       files := `
+-- hugo.toml --{}
+baseURL = "https://example.com"
+-- i18n/.keep --
+-- data/.keep --
+`
+       Test(t, files)
+}
index acdc674e63d590f1eb31eea970a9a03ca957de36..b7da065fdc5969d0cf59f7fe1cc7e2727dee2d6c 100644 (file)
@@ -249,9 +249,6 @@ func (c *pagesCollector) collectDir(dirPath *paths.Path, isDir bool, inFilter fu
 
 func (c *pagesCollector) collectDirDir(path string, root hugofs.FileMetaInfo, inFilter func(fim hugofs.FileMetaInfo) bool) error {
        filter := func(fim hugofs.FileMetaInfo) bool {
-               if c.sp.IgnoreFile(fim.Meta().Filename) {
-                       return false
-               }
                if inFilter != nil {
                        return inFilter(fim)
                }
@@ -330,13 +327,14 @@ func (c *pagesCollector) collectDirDir(path string, root hugofs.FileMetaInfo, in
 
        w := hugofs.NewWalkway(
                hugofs.WalkwayConfig{
-                       Logger:   c.logger,
-                       Root:     path,
-                       Info:     root,
-                       Fs:       c.fs,
-                       HookPre:  preHook,
-                       HookPost: postHook,
-                       WalkFn:   wfn,
+                       Logger:     c.logger,
+                       Root:       path,
+                       Info:       root,
+                       Fs:         c.fs,
+                       IgnoreFile: c.h.SourceSpec.IgnoreFile,
+                       HookPre:    preHook,
+                       HookPost:   postHook,
+                       WalkFn:     wfn,
                })
 
        return w.Walk()
@@ -371,6 +369,7 @@ func (c *pagesCollector) handleBundleLeaf(dir, bundle hugofs.FileMetaInfo, inPat
                        Logger:     c.logger,
                        Info:       dir,
                        DirEntries: readdir,
+                       IgnoreFile: c.h.SourceSpec.IgnoreFile,
                        WalkFn:     walk,
                })
 
index ab52474130057b4dcc7fbaff9bb4dc47e5c7d8f7..9bbd5d9f6b3c76985565a26142b8aa8677c4b3bd 100644 (file)
@@ -59,7 +59,8 @@ func (tp *TranslationProvider) NewResource(dst *deps.Deps) error {
 
        w := hugofs.NewWalkway(
                hugofs.WalkwayConfig{
-                       Fs: dst.BaseFs.I18n.Fs,
+                       Fs:         dst.BaseFs.I18n.Fs,
+                       IgnoreFile: dst.SourceSpec.IgnoreFile,
                        WalkFn: func(path string, info hugofs.FileMetaInfo) error {
                                if info.IsDir() {
                                        return nil