mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-27 14:10:31 +03: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:
parent
6aededf6b4
commit
241b21b0fd
337 changed files with 13377 additions and 14898 deletions
|
@ -3,6 +3,7 @@ package hugolib
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
@ -19,7 +20,9 @@ import (
|
|||
"github.com/gohugoio/hugo/common/herrors"
|
||||
"github.com/gohugoio/hugo/common/hexec"
|
||||
"github.com/gohugoio/hugo/common/loggers"
|
||||
"github.com/gohugoio/hugo/common/maps"
|
||||
"github.com/gohugoio/hugo/config"
|
||||
"github.com/gohugoio/hugo/config/allconfig"
|
||||
"github.com/gohugoio/hugo/config/security"
|
||||
"github.com/gohugoio/hugo/deps"
|
||||
"github.com/gohugoio/hugo/helpers"
|
||||
|
@ -194,10 +197,11 @@ func (s *IntegrationTestBuilder) Build() *IntegrationTestBuilder {
|
|||
if s.Cfg.Verbose || err != nil {
|
||||
fmt.Println(s.logBuff.String())
|
||||
}
|
||||
s.Assert(err, qt.IsNil)
|
||||
if s.Cfg.RunGC {
|
||||
s.GCCount, err = s.H.GC()
|
||||
}
|
||||
s.Assert(err, qt.IsNil)
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
|
@ -308,38 +312,57 @@ func (s *IntegrationTestBuilder) initBuilder() error {
|
|||
s.Assert(afero.WriteFile(afs, filename, data, 0666), qt.IsNil)
|
||||
}
|
||||
|
||||
configDirFilename := filepath.Join(s.Cfg.WorkingDir, "config")
|
||||
if _, err := afs.Stat(configDirFilename); err != nil {
|
||||
configDirFilename = ""
|
||||
configDir := "config"
|
||||
if _, err := afs.Stat(filepath.Join(s.Cfg.WorkingDir, "config")); err != nil {
|
||||
configDir = ""
|
||||
}
|
||||
|
||||
cfg, _, err := LoadConfig(
|
||||
ConfigSourceDescriptor{
|
||||
WorkingDir: s.Cfg.WorkingDir,
|
||||
AbsConfigDir: configDirFilename,
|
||||
Fs: afs,
|
||||
Logger: logger,
|
||||
Environ: []string{},
|
||||
},
|
||||
func(cfg config.Provider) error {
|
||||
return nil
|
||||
var flags config.Provider
|
||||
if s.Cfg.BaseCfg != nil {
|
||||
flags = s.Cfg.BaseCfg
|
||||
} else {
|
||||
flags = config.New()
|
||||
}
|
||||
|
||||
if s.Cfg.Running {
|
||||
flags.Set("internal", maps.Params{
|
||||
"running": s.Cfg.Running,
|
||||
})
|
||||
}
|
||||
|
||||
if s.Cfg.WorkingDir != "" {
|
||||
flags.Set("workingDir", s.Cfg.WorkingDir)
|
||||
}
|
||||
|
||||
res, err := allconfig.LoadConfig(
|
||||
allconfig.ConfigSourceDescriptor{
|
||||
Flags: flags,
|
||||
ConfigDir: configDir,
|
||||
Fs: afs,
|
||||
Logger: logger,
|
||||
Environ: s.Cfg.Environ,
|
||||
},
|
||||
)
|
||||
|
||||
s.Assert(err, qt.IsNil)
|
||||
if err != nil {
|
||||
initErr = err
|
||||
return
|
||||
}
|
||||
|
||||
cfg.Set("workingDir", s.Cfg.WorkingDir)
|
||||
|
||||
fs := hugofs.NewFrom(afs, cfg)
|
||||
fs := hugofs.NewFrom(afs, res.LoadingInfo.BaseConfig)
|
||||
|
||||
s.Assert(err, qt.IsNil)
|
||||
|
||||
depsCfg := deps.DepsCfg{Cfg: cfg, Fs: fs, Running: s.Cfg.Running, Logger: logger}
|
||||
depsCfg := deps.DepsCfg{Configs: res, Fs: fs, Logger: logger}
|
||||
sites, err := NewHugoSites(depsCfg)
|
||||
if err != nil {
|
||||
initErr = err
|
||||
return
|
||||
}
|
||||
if sites == nil {
|
||||
initErr = errors.New("no sites")
|
||||
return
|
||||
}
|
||||
|
||||
s.H = sites
|
||||
s.fs = fs
|
||||
|
@ -482,6 +505,12 @@ type IntegrationTestConfig struct {
|
|||
// https://pkg.go.dev/golang.org/x/exp/cmd/txtar
|
||||
TxtarString string
|
||||
|
||||
// COnfig to use as the base. We will also read the config from the txtar.
|
||||
BaseCfg config.Provider
|
||||
|
||||
// Environment variables passed to the config loader.
|
||||
Environ []string
|
||||
|
||||
// Whether to simulate server mode.
|
||||
Running bool
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue