Filter dot files etc. in i18n - hugo - [fork] hugo port for 9front
(HTM) git clone git@git.drkhsh.at/hugo.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Submodules
(DIR) README
(DIR) LICENSE
---
(DIR) commit 9df7b295bcfb59000f6ee675dfbbc53654f3d86c
(DIR) parent c37bf19c898035de1518c3f2ab4380f08817151f
(HTM) Author: Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Date: Mon, 5 Feb 2024 14:54:02 +0100
Filter dot files etc. in i18n
Closes #11993
Diffstat:
M hugofs/walk.go | 16 ++++++++++++++--
M hugolib/hugo_sites.go | 3 ++-
M hugolib/language_test.go | 11 +++++++++++
M hugolib/pages_capture.go | 19 +++++++++----------
M langs/i18n/translationProvider.go | 3 ++-
5 files changed, 38 insertions(+), 14 deletions(-)
---
(DIR) diff --git a/hugofs/walk.go b/hugofs/walk.go
@@ -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)
(DIR) diff --git a/hugolib/hugo_sites.go b/hugolib/hugo_sites.go
@@ -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
(DIR) diff --git a/hugolib/language_test.go b/hugolib/language_test.go
@@ -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)
+}
(DIR) diff --git a/hugolib/pages_capture.go b/hugolib/pages_capture.go
@@ -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,
})
(DIR) diff --git a/langs/i18n/translationProvider.go b/langs/i18n/translationProvider.go
@@ -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