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

@@ -33,17 +33,14 @@ import (
// New returns a new instance of the strings-namespaced template functions.
func New(d *deps.Deps) *Namespace {
titleCaseStyle := d.Cfg.GetString("titleCaseStyle")
titleFunc := helpers.GetTitleFunc(titleCaseStyle)
return &Namespace{deps: d, titleFunc: titleFunc}
return &Namespace{deps: d}
}
// Namespace provides template functions for the "strings" namespace.
// Most functions mimic the Go stdlib, but the order of the parameters may be
// different to ease their use in the Go template system.
type Namespace struct {
titleFunc func(s string) string
deps *deps.Deps
deps *deps.Deps
}
// CountRunes returns the number of runes in s, excluding whitespace.
@@ -163,6 +160,7 @@ func (ns *Namespace) ContainsAny(s, chars any) (bool, error) {
// ContainsNonSpace reports whether s contains any non-space characters as defined
// by Unicode's White Space property,
// <docsmeta>{"newIn": "0.111.0" }</docsmeta>
func (ns *Namespace) ContainsNonSpace(s any) bool {
ss := cast.ToString(s)
@@ -383,8 +381,7 @@ func (ns *Namespace) Title(s any) (string, error) {
if err != nil {
return "", err
}
return ns.titleFunc(ss), nil
return ns.deps.Conf.CreateTitle(ss), nil
}
// FirstUpper converts s making the first character upper case.