summaryrefslogtreecommitdiffstats
path: root/source/sourceSpec.go
diff options
context:
space:
mode:
Diffstat (limited to 'source/sourceSpec.go')
-rw-r--r--source/sourceSpec.go27
1 files changed, 18 insertions, 9 deletions
diff --git a/source/sourceSpec.go b/source/sourceSpec.go
index e40010162..634306e5f 100644
--- a/source/sourceSpec.go
+++ b/source/sourceSpec.go
@@ -18,17 +18,18 @@ import (
"path/filepath"
"regexp"
- "github.com/gohugoio/hugo/config"
+ "github.com/spf13/afero"
+
"github.com/gohugoio/hugo/helpers"
- "github.com/gohugoio/hugo/hugofs"
"github.com/spf13/cast"
)
// SourceSpec abstracts language-specific file creation.
// TODO(bep) rename to Spec
type SourceSpec struct {
- Cfg config.Provider
- Fs *hugofs.Fs
+ *helpers.PathSpec
+
+ Fs afero.Fs
// This is set if the ignoreFiles config is set.
ignoreFilesRe []*regexp.Regexp
@@ -38,8 +39,9 @@ type SourceSpec struct {
DisabledLanguages map[string]bool
}
-// NewSourceSpec initializes SourceSpec using languages from a given configuration.
-func NewSourceSpec(cfg config.Provider, fs *hugofs.Fs) *SourceSpec {
+// NewSourceSpec initializes SourceSpec using languages the given filesystem and PathSpec.
+func NewSourceSpec(ps *helpers.PathSpec, fs afero.Fs) *SourceSpec {
+ cfg := ps.Cfg
defaultLang := cfg.GetString("defaultContentLanguage")
languages := cfg.GetStringMap("languages")
@@ -69,10 +71,17 @@ func NewSourceSpec(cfg config.Provider, fs *hugofs.Fs) *SourceSpec {
}
}
- return &SourceSpec{ignoreFilesRe: regexps, Cfg: cfg, Fs: fs, Languages: languages, DefaultContentLanguage: defaultLang, DisabledLanguages: disabledLangsSet}
+ return &SourceSpec{ignoreFilesRe: regexps, PathSpec: ps, Fs: fs, Languages: languages, DefaultContentLanguage: defaultLang, DisabledLanguages: disabledLangsSet}
}
func (s *SourceSpec) IgnoreFile(filename string) bool {
+ if filename == "" {
+ if _, ok := s.Fs.(*afero.OsFs); ok {
+ return true
+ }
+ return false
+ }
+
base := filepath.Base(filename)
if len(base) > 0 {
@@ -99,7 +108,7 @@ func (s *SourceSpec) IgnoreFile(filename string) bool {
}
func (s *SourceSpec) IsRegularSourceFile(filename string) (bool, error) {
- fi, err := helpers.LstatIfOs(s.Fs.Source, filename)
+ fi, err := helpers.LstatIfPossible(s.Fs, filename)
if err != nil {
return false, err
}
@@ -110,7 +119,7 @@ func (s *SourceSpec) IsRegularSourceFile(filename string) (bool, error) {
if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
link, err := filepath.EvalSymlinks(filename)
- fi, err = helpers.LstatIfOs(s.Fs.Source, link)
+ fi, err = helpers.LstatIfPossible(s.Fs, link)
if err != nil {
return false, err
}