mirror of
https://github.com/gohugoio/hugo.git
synced 2025-09-01 22:42:45 +02:00
Create a struct with all of Hugo's config options
Primary motivation is documentation, but it will also hopefully simplify the code. Also, * Lower case the default output format names; this is in line with the custom ones (map keys) and how it's treated all the places. This avoids doing `stringds.EqualFold` everywhere. Closes #10896 Closes #10620
This commit is contained in:
@@ -42,8 +42,8 @@ import (
|
||||
func New(deps *deps.Deps) *Namespace {
|
||||
return &Namespace{
|
||||
deps: deps,
|
||||
cacheGetCSV: deps.FileCaches.GetCSVCache(),
|
||||
cacheGetJSON: deps.FileCaches.GetJSONCache(),
|
||||
cacheGetCSV: deps.ResourceSpec.FileCaches.GetCSVCache(),
|
||||
cacheGetJSON: deps.ResourceSpec.FileCaches.GetJSONCache(),
|
||||
client: http.DefaultClient,
|
||||
}
|
||||
}
|
||||
|
@@ -98,7 +98,7 @@ func TestGetCSV(t *testing.T) {
|
||||
|
||||
// Setup local test file for schema-less URLs
|
||||
if !strings.Contains(test.url, ":") && !strings.HasPrefix(test.url, "fail/") {
|
||||
f, err := ns.deps.Fs.Source.Create(filepath.Join(ns.deps.Cfg.GetString("workingDir"), test.url))
|
||||
f, err := ns.deps.Fs.Source.Create(filepath.Join(ns.deps.Conf.BaseConfig().WorkingDir, test.url))
|
||||
c.Assert(err, qt.IsNil, msg)
|
||||
f.WriteString(test.content)
|
||||
f.Close()
|
||||
@@ -190,7 +190,7 @@ func TestGetJSON(t *testing.T) {
|
||||
|
||||
// Setup local test file for schema-less URLs
|
||||
if !strings.Contains(test.url, ":") && !strings.HasPrefix(test.url, "fail/") {
|
||||
f, err := ns.deps.Fs.Source.Create(filepath.Join(ns.deps.Cfg.GetString("workingDir"), test.url))
|
||||
f, err := ns.deps.Fs.Source.Create(filepath.Join(ns.deps.Conf.BaseConfig().WorkingDir, test.url))
|
||||
c.Assert(err, qt.IsNil, msg)
|
||||
f.WriteString(test.content)
|
||||
f.Close()
|
||||
|
@@ -24,7 +24,6 @@ import (
|
||||
|
||||
"github.com/gohugoio/hugo/cache/filecache"
|
||||
|
||||
"github.com/gohugoio/hugo/config"
|
||||
"github.com/gohugoio/hugo/helpers"
|
||||
"github.com/spf13/afero"
|
||||
)
|
||||
@@ -100,8 +99,8 @@ func (ns *Namespace) getRemote(cache *filecache.Cache, unmarshal func([]byte) (b
|
||||
}
|
||||
|
||||
// getLocal loads the content of a local file
|
||||
func getLocal(url string, fs afero.Fs, cfg config.Provider) ([]byte, error) {
|
||||
filename := filepath.Join(cfg.GetString("workingDir"), url)
|
||||
func getLocal(workingDir, url string, fs afero.Fs) ([]byte, error) {
|
||||
filename := filepath.Join(workingDir, url)
|
||||
return afero.ReadFile(fs, filename)
|
||||
}
|
||||
|
||||
@@ -114,7 +113,7 @@ func (ns *Namespace) getResource(cache *filecache.Cache, unmarshal func(b []byte
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b, err := getLocal(url, ns.deps.Fs.Source, ns.deps.Cfg)
|
||||
b, err := getLocal(ns.deps.Conf.BaseConfig().WorkingDir, url, ns.deps.Fs.Source)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -18,30 +18,31 @@ import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gohugoio/hugo/config/security"
|
||||
"github.com/gohugoio/hugo/modules"
|
||||
"github.com/gohugoio/hugo/config/testconfig"
|
||||
|
||||
"github.com/gohugoio/hugo/helpers"
|
||||
|
||||
qt "github.com/frankban/quicktest"
|
||||
"github.com/gohugoio/hugo/cache/filecache"
|
||||
"github.com/gohugoio/hugo/common/hexec"
|
||||
"github.com/gohugoio/hugo/common/loggers"
|
||||
"github.com/gohugoio/hugo/config"
|
||||
"github.com/gohugoio/hugo/deps"
|
||||
"github.com/gohugoio/hugo/hugofs"
|
||||
"github.com/gohugoio/hugo/langs"
|
||||
"github.com/spf13/afero"
|
||||
)
|
||||
|
||||
func TestScpGetLocal(t *testing.T) {
|
||||
t.Parallel()
|
||||
v := config.NewWithTestDefaults()
|
||||
fs := hugofs.NewMem(v)
|
||||
v := config.New()
|
||||
workingDir := "/my/working/dir"
|
||||
v.Set("workingDir", workingDir)
|
||||
v.Set("publishDir", "public")
|
||||
fs := hugofs.NewFromOld(afero.NewMemMapFs(), v)
|
||||
ps := helpers.FilePathSeparator
|
||||
|
||||
tests := []struct {
|
||||
@@ -57,12 +58,12 @@ func TestScpGetLocal(t *testing.T) {
|
||||
|
||||
for _, test := range tests {
|
||||
r := bytes.NewReader(test.content)
|
||||
err := helpers.WriteToDisk(test.path, r, fs.Source)
|
||||
err := helpers.WriteToDisk(filepath.Join(workingDir, test.path), r, fs.Source)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
c, err := getLocal(test.path, fs.Source, v)
|
||||
c, err := getLocal(workingDir, test.path, fs.Source)
|
||||
if err != nil {
|
||||
t.Errorf("Error getting resource content: %s", err)
|
||||
}
|
||||
@@ -145,7 +146,7 @@ func TestScpGetRemoteParallel(t *testing.T) {
|
||||
c.Assert(err, qt.IsNil)
|
||||
|
||||
for _, ignoreCache := range []bool{false} {
|
||||
cfg := config.NewWithTestDefaults()
|
||||
cfg := config.New()
|
||||
cfg.Set("ignoreCache", ignoreCache)
|
||||
|
||||
ns := New(newDeps(cfg))
|
||||
@@ -180,51 +181,21 @@ func TestScpGetRemoteParallel(t *testing.T) {
|
||||
}
|
||||
|
||||
func newDeps(cfg config.Provider) *deps.Deps {
|
||||
cfg.Set("resourceDir", "resources")
|
||||
cfg.Set("dataDir", "resources")
|
||||
cfg.Set("i18nDir", "i18n")
|
||||
cfg.Set("assetDir", "assets")
|
||||
cfg.Set("layoutDir", "layouts")
|
||||
cfg.Set("archetypeDir", "archetypes")
|
||||
conf := testconfig.GetTestConfig(nil, cfg)
|
||||
logger := loggers.NewIgnorableLogger(loggers.NewErrorLogger(), nil)
|
||||
fs := hugofs.NewFrom(afero.NewMemMapFs(), conf.BaseConfig())
|
||||
|
||||
langs.LoadLanguageSettings(cfg, nil)
|
||||
mod, err := modules.CreateProjectModule(cfg)
|
||||
if err != nil {
|
||||
d := &deps.Deps{
|
||||
Fs: fs,
|
||||
Log: logger,
|
||||
Conf: conf,
|
||||
}
|
||||
if err := d.Init(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
cfg.Set("allModules", modules.Modules{mod})
|
||||
|
||||
ex := hexec.New(security.DefaultConfig)
|
||||
|
||||
logger := loggers.NewIgnorableLogger(loggers.NewErrorLogger(), "none")
|
||||
cs, err := helpers.NewContentSpec(cfg, logger, afero.NewMemMapFs(), ex)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fs := hugofs.NewMem(cfg)
|
||||
|
||||
p, err := helpers.NewPathSpec(fs, cfg, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fileCaches, err := filecache.NewCaches(p)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return &deps.Deps{
|
||||
Cfg: cfg,
|
||||
Fs: fs,
|
||||
FileCaches: fileCaches,
|
||||
ExecHelper: ex,
|
||||
ContentSpec: cs,
|
||||
Log: logger,
|
||||
LogDistinct: helpers.NewDistinctLogger(logger),
|
||||
}
|
||||
return d
|
||||
}
|
||||
|
||||
func newTestNs() *Namespace {
|
||||
return New(newDeps(config.NewWithTestDefaults()))
|
||||
return New(newDeps(config.New()))
|
||||
}
|
||||
|
Reference in New Issue
Block a user