aboutsummaryrefslogtreecommitdiffhomepage
path: root/source
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2021-10-13 08:12:06 +0200
committerBjørn Erik Pedersen <[email protected]>2021-10-16 15:22:03 +0200
commit9185e11effa682ea1ef7dc98f2943743671023a6 (patch)
treef89d4138ddffd163a2afcd814ed2c26d3c66c4c9 /source
parent168a3aab4622786ccd0943137fce3912707f2a46 (diff)
downloadhugo-9185e11effa682ea1ef7dc98f2943743671023a6.tar.gz
hugo-9185e11effa682ea1ef7dc98f2943743671023a6.zip
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')
-rw-r--r--source/content_directory_test.go2
-rw-r--r--source/filesystem_test.go2
-rw-r--r--source/sourceSpec.go36
3 files changed, 22 insertions, 18 deletions
diff --git a/source/content_directory_test.go b/source/content_directory_test.go
index d3723c6b1..8f1d0df4f 100644
--- a/source/content_directory_test.go
+++ b/source/content_directory_test.go
@@ -57,7 +57,7 @@ func TestIgnoreDotFilesAndDirectories(t *testing.T) {
ps, err := helpers.NewPathSpec(fs, v, nil)
c.Assert(err, qt.IsNil)
- s := NewSourceSpec(ps, fs.Source)
+ s := NewSourceSpec(ps, nil, fs.Source)
if ignored := s.IgnoreFile(filepath.FromSlash(test.path)); test.ignore != ignored {
t.Errorf("[%d] File not ignored", i)
diff --git a/source/filesystem_test.go b/source/filesystem_test.go
index 0b8c1d395..6343c6a41 100644
--- a/source/filesystem_test.go
+++ b/source/filesystem_test.go
@@ -106,5 +106,5 @@ func newTestSourceSpec() *SourceSpec {
if err != nil {
panic(err)
}
- return NewSourceSpec(ps, fs.Source)
+ return NewSourceSpec(ps, nil, fs.Source)
}
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
}
}
}