mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-17 21:01:26 +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:
@@ -71,8 +71,10 @@ var (
|
||||
)
|
||||
|
||||
type templateExecHelper struct {
|
||||
running bool // whether we're in server mode.
|
||||
funcs map[string]reflect.Value
|
||||
running bool // whether we're in server mode.
|
||||
site reflect.Value
|
||||
siteParams reflect.Value
|
||||
funcs map[string]reflect.Value
|
||||
}
|
||||
|
||||
func (t *templateExecHelper) GetFunc(ctx context.Context, tmpl texttemplate.Preparer, name string) (fn reflect.Value, firstArg reflect.Value, found bool) {
|
||||
@@ -111,6 +113,8 @@ func (t *templateExecHelper) GetMapValue(ctx context.Context, tmpl texttemplate.
|
||||
return v, v.IsValid()
|
||||
}
|
||||
|
||||
var typeParams = reflect.TypeOf(maps.Params{})
|
||||
|
||||
func (t *templateExecHelper) GetMethod(ctx context.Context, tmpl texttemplate.Preparer, receiver reflect.Value, name string) (method reflect.Value, firstArg reflect.Value) {
|
||||
if t.running {
|
||||
switch name {
|
||||
@@ -123,6 +127,13 @@ func (t *templateExecHelper) GetMethod(ctx context.Context, tmpl texttemplate.Pr
|
||||
}
|
||||
}
|
||||
|
||||
if strings.EqualFold(name, "mainsections") && receiver.Type() == typeParams && receiver.Pointer() == t.siteParams.Pointer() {
|
||||
// MOved to site.MainSections in Hugo 0.112.0.
|
||||
receiver = t.site
|
||||
name = "MainSections"
|
||||
|
||||
}
|
||||
|
||||
fn := hreflect.GetMethodByName(receiver, name)
|
||||
if !fn.IsValid() {
|
||||
return zero, zero
|
||||
@@ -167,8 +178,10 @@ func newTemplateExecuter(d *deps.Deps) (texttemplate.Executer, map[string]reflec
|
||||
}
|
||||
|
||||
exeHelper := &templateExecHelper{
|
||||
running: d.Running,
|
||||
funcs: funcsv,
|
||||
running: d.Conf.Running(),
|
||||
funcs: funcsv,
|
||||
site: reflect.ValueOf(d.Site),
|
||||
siteParams: reflect.ValueOf(d.Site.Params()),
|
||||
}
|
||||
|
||||
return texttemplate.NewExecuter(
|
||||
|
Reference in New Issue
Block a user