summaryrefslogtreecommitdiffstats
path: root/source/sourceSpec.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-10-13 08:12:06 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2021-10-16 15:22:03 +0200
commit9185e11effa682ea1ef7dc98f2943743671023a6 (patch)
treef89d4138ddffd163a2afcd814ed2c26d3c66c4c9 /source/sourceSpec.go
parent168a3aab4622786ccd0943137fce3912707f2a46 (diff)
Reimplement archetypes
The old implementation had some issues, mostly related to the context (e.g. name, file paths) passed to the template. This new implementation is using the exact same code path for evaluating the pages as in a regular build. This also makes it more robust and easier to reason about in a multilingual setup. Now, if you are explicit about the target path, Hugo will now always pick the correct mount and language: ```bash hugo new content/en/posts/my-first-post.md ``` Fixes #9032 Fixes #7589 Fixes #9043 Fixes #9046 Fixes #9047
Diffstat (limited to 'source/sourceSpec.go')
-rw-r--r--source/sourceSpec.go36
1 files changed, 20 insertions, 16 deletions
diff --git a/source/sourceSpec.go b/source/sourceSpec.go
index e8407a14d..3640c83d5 100644
--- a/source/sourceSpec.go
+++ b/source/sourceSpec.go
@@ -19,6 +19,8 @@ import (
"regexp"
"runtime"
+ "github.com/gohugoio/hugo/hugofs/glob"
+
"github.com/gohugoio/hugo/langs"
"github.com/spf13/afero"
@@ -33,8 +35,7 @@ type SourceSpec struct {
SourceFs afero.Fs
- // This is set if the ignoreFiles config is set.
- ignoreFilesRe []*regexp.Regexp
+ shouldInclude func(filename string) bool
Languages map[string]interface{}
DefaultContentLanguage string
@@ -42,7 +43,7 @@ type SourceSpec struct {
}
// NewSourceSpec initializes SourceSpec using languages the given filesystem and PathSpec.
-func NewSourceSpec(ps *helpers.PathSpec, fs afero.Fs) *SourceSpec {
+func NewSourceSpec(ps *helpers.PathSpec, inclusionFilter *glob.FilenameFilter, fs afero.Fs) *SourceSpec {
cfg := ps.Cfg
defaultLang := cfg.GetString("defaultContentLanguage")
languages := cfg.GetStringMap("languages")
@@ -72,8 +73,19 @@ func NewSourceSpec(ps *helpers.PathSpec, fs afero.Fs) *SourceSpec {
}
}
+ shouldInclude := func(filename string) bool {
+ if !inclusionFilter.Match(filename) {
+ return false
+ }
+ for _, r := range regexps {
+ if r.MatchString(filename) {
+ return false
+ }
+ }
+ return true
+ }
- return &SourceSpec{ignoreFilesRe: regexps, PathSpec: ps, SourceFs: fs, Languages: languages, DefaultContentLanguage: defaultLang, DisabledLanguages: disabledLangsSet}
+ return &SourceSpec{shouldInclude: shouldInclude, PathSpec: ps, SourceFs: fs, Languages: languages, DefaultContentLanguage: defaultLang, DisabledLanguages: disabledLangsSet}
}
// IgnoreFile returns whether a given file should be ignored.
@@ -97,24 +109,16 @@ func (s *SourceSpec) IgnoreFile(filename string) bool {
}
}
- if len(s.ignoreFilesRe) == 0 {
- return false
- }
-
- for _, re := range s.ignoreFilesRe {
- if re.MatchString(filename) {
- return true
- }
+ if !s.shouldInclude(filename) {
+ return true
}
if runtime.GOOS == "windows" {
// Also check the forward slash variant if different.
unixFilename := filepath.ToSlash(filename)
if unixFilename != filename {
- for _, re := range s.ignoreFilesRe {
- if re.MatchString(unixFilename) {
- return true
- }
+ if !s.shouldInclude(unixFilename) {
+ return true
}
}
}