diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-02-05 10:20:06 +0700 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2017-02-17 17:15:26 +0100 |
commit | 93ca7c9e958e34469a337e4efcc7c75774ec50fd (patch) | |
tree | 5dfa296cfe74fd5ef8f0d41ea4078704f453aa04 /helpers/pathspec.go | |
parent | e34af6ee30f70f5780a281e2fd8f4ed9b487ee61 (diff) |
all: Refactor to nonglobal Viper, i18n etc.
This is a final rewrite that removes all the global state in Hugo, which also enables
the use if `t.Parallel` in tests.
Updates #2701
Fixes #3016
Diffstat (limited to 'helpers/pathspec.go')
-rw-r--r-- | helpers/pathspec.go | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/helpers/pathspec.go b/helpers/pathspec.go index 0fc957b3b..ddc183380 100644 --- a/helpers/pathspec.go +++ b/helpers/pathspec.go @@ -16,6 +16,7 @@ package helpers import ( "fmt" + "github.com/spf13/hugo/config" "github.com/spf13/hugo/hugofs" ) @@ -26,11 +27,20 @@ type PathSpec struct { uglyURLs bool canonifyURLs bool - currentContentLanguage *Language + language *Language // pagination path handling paginatePath string + baseURL string + theme string + + // Directories + themesDir string + layoutDir string + workingDir string + staticDir string + // The PathSpec looks up its config settings in both the current language // and then in the global Viper config. // Some settings, the settings listed below, does not make sense to be set @@ -45,31 +55,35 @@ type PathSpec struct { } func (p PathSpec) String() string { - return fmt.Sprintf("PathSpec, language %q, prefix %q, multilingual: %T", p.currentContentLanguage.Lang, p.getLanguagePrefix(), p.multilingual) + return fmt.Sprintf("PathSpec, language %q, prefix %q, multilingual: %T", p.language.Lang, p.getLanguagePrefix(), p.multilingual) } -// NewPathSpec creats a new PathSpec from the given filesystems and ConfigProvider. -func NewPathSpec(fs *hugofs.Fs, config ConfigProvider) *PathSpec { - - currCl, ok := config.Get("currentContentLanguage").(*Language) +// NewPathSpec creats a new PathSpec from the given filesystems and Language. +func NewPathSpec(fs *hugofs.Fs, cfg config.Provider) *PathSpec { - if !ok { - // TODO(bep) globals - currCl = NewLanguage("en") + ps := &PathSpec{ + fs: fs, + disablePathToLower: cfg.GetBool("disablePathToLower"), + removePathAccents: cfg.GetBool("removePathAccents"), + uglyURLs: cfg.GetBool("uglyURLs"), + canonifyURLs: cfg.GetBool("canonifyURLs"), + multilingual: cfg.GetBool("multilingual"), + defaultContentLanguageInSubdir: cfg.GetBool("defaultContentLanguageInSubdir"), + defaultContentLanguage: cfg.GetString("defaultContentLanguage"), + paginatePath: cfg.GetString("paginatePath"), + baseURL: cfg.GetString("baseURL"), + themesDir: cfg.GetString("themesDir"), + layoutDir: cfg.GetString("layoutDir"), + workingDir: cfg.GetString("workingDir"), + staticDir: cfg.GetString("staticDir"), + theme: cfg.GetString("theme"), } - return &PathSpec{ - fs: fs, - disablePathToLower: config.GetBool("disablePathToLower"), - removePathAccents: config.GetBool("removePathAccents"), - uglyURLs: config.GetBool("uglyURLs"), - canonifyURLs: config.GetBool("canonifyURLs"), - multilingual: config.GetBool("multilingual"), - defaultContentLanguageInSubdir: config.GetBool("defaultContentLanguageInSubdir"), - defaultContentLanguage: config.GetString("defaultContentLanguage"), - currentContentLanguage: currCl, - paginatePath: config.GetString("paginatePath"), + if language, ok := cfg.(*Language); ok { + ps.language = language } + + return ps } // PaginatePath returns the configured root path used for paginator pages. |