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:
Bjørn Erik Pedersen
2023-01-04 18:24:36 +01:00
parent 6aededf6b4
commit 241b21b0fd
337 changed files with 13377 additions and 14898 deletions

View File

@@ -15,7 +15,6 @@ package hugolib
import (
"fmt"
"html/template"
"path/filepath"
"testing"
@@ -39,44 +38,19 @@ var urlFakeSource = [][2]string{
{filepath.FromSlash("content/blue/doc2.md"), slugDoc2},
}
// Issue #1105
func TestShouldNotAddTrailingSlashToBaseURL(t *testing.T) {
t.Parallel()
c := qt.New(t)
for i, this := range []struct {
in string
expected string
}{
{"http://base.com/", "http://base.com/"},
{"http://base.com/sub/", "http://base.com/sub/"},
{"http://base.com/sub", "http://base.com/sub"},
{"http://base.com", "http://base.com"},
} {
cfg, fs := newTestCfg()
cfg.Set("baseURL", this.in)
d := deps.DepsCfg{Cfg: cfg, Fs: fs}
s, err := NewSiteForCfg(d)
c.Assert(err, qt.IsNil)
c.Assert(s.initializeSiteInfo(), qt.IsNil)
if s.Info.BaseURL() != template.URL(this.expected) {
t.Errorf("[%d] got %s expected %s", i, s.Info.BaseURL(), this.expected)
}
}
}
func TestPageCount(t *testing.T) {
t.Parallel()
c := qt.New(t)
cfg, fs := newTestCfg()
cfg.Set("uglyURLs", false)
cfg.Set("paginate", 10)
configs, err := loadTestConfigFromProvider(cfg)
c.Assert(err, qt.IsNil)
writeSourcesToSource(t, "", fs, urlFakeSource...)
s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Configs: configs}, BuildCfg{})
_, err := s.Fs.WorkingDirReadOnly.Open("public/blue")
_, err = s.Fs.WorkingDirReadOnly.Open("public/blue")
if err != nil {
t.Errorf("No indexed rendered.")
}
@@ -113,11 +87,13 @@ Do not go gentle into that good night.
cfg.Set("uglyURLs", map[string]bool{
"sect2": true,
})
configs, err := loadTestConfigFromProvider(cfg)
c.Assert(err, qt.IsNil)
writeSource(t, fs, filepath.Join("content", "sect1", "p1.md"), dt)
writeSource(t, fs, filepath.Join("content", "sect2", "p2.md"), dt)
s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true})
s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Configs: configs}, BuildCfg{SkipRender: true})
c.Assert(len(s.RegularPages()), qt.Equals, 2)
@@ -159,9 +135,8 @@ Do not go gentle into that good night.
`
cfg, fs := newTestCfg()
th := newTestHelper(cfg, fs, t)
cfg.Set("paginate", 1)
th, configs := newTestHelperFromProvider(cfg, fs, t)
writeSource(t, fs, filepath.Join("content", "sect1", "_index.md"), fmt.Sprintf(st, "/ss1/"))
writeSource(t, fs, filepath.Join("content", "sect2", "_index.md"), fmt.Sprintf(st, "/ss2/"))
@@ -175,7 +150,7 @@ Do not go gentle into that good night.
writeSource(t, fs, filepath.Join("layouts", "_default", "list.html"),
"<html><body>P{{.Paginator.PageNumber}}|URL: {{.Paginator.URL}}|{{ if .Paginator.HasNext }}Next: {{.Paginator.Next.URL }}{{ end }}</body></html>")
s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Configs: configs}, BuildCfg{})
c.Assert(len(s.RegularPages()), qt.Equals, 10)