From 4174a7866b75c6ae10827cc77dbae0676af8e5eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 1 Feb 2024 09:37:05 +0100 Subject: Fix disabled languages regression Fixes #11959 --- hugofs/component_fs.go | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) (limited to 'hugofs') diff --git a/hugofs/component_fs.go b/hugofs/component_fs.go index 62d977ae8..e75e23f84 100644 --- a/hugofs/component_fs.go +++ b/hugofs/component_fs.go @@ -94,11 +94,15 @@ func (f *componentFsDir) ReadDir(count int) ([]iofs.DirEntry, error) { fis = fis[:n] + n = 0 for _, fi := range fis { s := path.Join(f.name, fi.Name()) - _ = f.fs.applyMeta(fi, s) - + if _, ok := f.fs.applyMeta(fi, s); ok { + fis[n] = fi + n++ + } } + fis = fis[:n] sort.Slice(fis, func(i, j int) bool { fimi, fimj := fis[i].(FileMetaInfo), fis[j].(FileMetaInfo) @@ -180,7 +184,8 @@ func (f *componentFsDir) Stat() (iofs.FileInfo, error) { if err != nil { return nil, err } - return f.fs.applyMeta(fi, f.name), nil + fim, _ := f.fs.applyMeta(fi, f.name) + return fim, nil } func (fs *componentFs) Stat(name string) (os.FileInfo, error) { @@ -188,16 +193,26 @@ func (fs *componentFs) Stat(name string) (os.FileInfo, error) { if err != nil { return nil, err } - return fs.applyMeta(fi, name), nil + fim, _ := fs.applyMeta(fi, name) + return fim, nil } -func (fs *componentFs) applyMeta(fi FileNameIsDir, name string) FileMetaInfo { +func (fs *componentFs) applyMeta(fi FileNameIsDir, name string) (FileMetaInfo, bool) { if runtime.GOOS == "darwin" { name = norm.NFC.String(name) } fim := fi.(FileMetaInfo) meta := fim.Meta() - meta.PathInfo = fs.opts.PathParser.Parse(fs.opts.Component, name) + pi := fs.opts.PathParser.Parse(fs.opts.Component, name) + if pi.Disabled() { + return fim, false + } + if meta.Lang != "" { + if isLangDisabled := fs.opts.PathParser.IsLangDisabled; isLangDisabled != nil && isLangDisabled(meta.Lang) { + return fim, false + } + } + meta.PathInfo = pi if !fim.IsDir() { if fileLang := meta.PathInfo.Lang(); fileLang != "" { // A valid lang set in filename. @@ -223,7 +238,7 @@ func (fs *componentFs) applyMeta(fi FileNameIsDir, name string) FileMetaInfo { } } - return fim + return fim, true } func (f *componentFsDir) Readdir(count int) ([]os.FileInfo, error) { -- cgit v1.2.3