mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-28 12:40:49 +00:00
241b21b0fd
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
49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
package helpers_test
|
|
|
|
import (
|
|
"github.com/gohugoio/hugo/common/loggers"
|
|
"github.com/gohugoio/hugo/config"
|
|
"github.com/gohugoio/hugo/config/testconfig"
|
|
"github.com/gohugoio/hugo/helpers"
|
|
"github.com/gohugoio/hugo/hugofs"
|
|
"github.com/spf13/afero"
|
|
)
|
|
|
|
func newTestPathSpecFromCfgAndLang(cfg config.Provider, lang string) *helpers.PathSpec {
|
|
mfs := afero.NewMemMapFs()
|
|
|
|
configs := testconfig.GetTestConfigs(mfs, cfg)
|
|
var conf config.AllProvider
|
|
if lang == "" {
|
|
conf = configs.GetFirstLanguageConfig()
|
|
} else {
|
|
conf = configs.GetByLang(lang)
|
|
if conf == nil {
|
|
panic("no config for lang " + lang)
|
|
}
|
|
}
|
|
fs := hugofs.NewFrom(mfs, conf.BaseConfig())
|
|
ps, err := helpers.NewPathSpec(fs, conf, loggers.NewErrorLogger())
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return ps
|
|
}
|
|
|
|
func newTestPathSpec(configKeyValues ...any) *helpers.PathSpec {
|
|
cfg := config.New()
|
|
for i := 0; i < len(configKeyValues); i += 2 {
|
|
cfg.Set(configKeyValues[i].(string), configKeyValues[i+1])
|
|
}
|
|
return newTestPathSpecFromCfgAndLang(cfg, "")
|
|
}
|
|
|
|
func newTestContentSpec(cfg config.Provider) *helpers.ContentSpec {
|
|
fs := afero.NewMemMapFs()
|
|
conf := testconfig.GetTestConfig(fs, cfg)
|
|
spec, err := helpers.NewContentSpec(conf, loggers.NewErrorLogger(), fs, nil)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return spec
|
|
}
|