Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tpl
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-09-07 16:07:10 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2020-09-07 22:06:44 +0300
commit4055c121847847d8bd6b95a928185daee065091b (patch)
tree6620f51e7e89aa7ff0a9a93361d640ee5b297fea /tpl
parent3ba7c92530a80f2f04fe57705ab05c247a6e8437 (diff)
Fix some change detection issues on server reloads
* Fix change detection when .GetPage/site.GetPage is used from shortcode * Fix stale content for GetPage results with short name lookups on server reloads Fixes #7623 Fixes #7624 Fixes #7625
Diffstat (limited to 'tpl')
-rw-r--r--tpl/fmt/fmt.go9
-rw-r--r--tpl/tplimpl/template_funcs.go23
2 files changed, 21 insertions, 11 deletions
diff --git a/tpl/fmt/fmt.go b/tpl/fmt/fmt.go
index aa6b8c1a6..924d27a1d 100644
--- a/tpl/fmt/fmt.go
+++ b/tpl/fmt/fmt.go
@@ -23,10 +23,17 @@ import (
// New returns a new instance of the fmt-namespaced template functions.
func New(d *deps.Deps) *Namespace {
- return &Namespace{
+ ns := &Namespace{
errorLogger: helpers.NewDistinctLogger(d.Log.ERROR),
warnLogger: helpers.NewDistinctLogger(d.Log.WARN),
}
+
+ d.BuildStartListeners.Add(func() {
+ ns.errorLogger.Reset()
+ ns.warnLogger.Reset()
+ })
+
+ return ns
}
// Namespace provides template functions for the "fmt" namespace.
diff --git a/tpl/tplimpl/template_funcs.go b/tpl/tplimpl/template_funcs.go
index a688abb77..25ace365d 100644
--- a/tpl/tplimpl/template_funcs.go
+++ b/tpl/tplimpl/template_funcs.go
@@ -64,7 +64,8 @@ var _ texttemplate.ExecHelper = (*templateExecHelper)(nil)
var zero reflect.Value
type templateExecHelper struct {
- funcs map[string]reflect.Value
+ running bool // whether we're in server mode.
+ funcs map[string]reflect.Value
}
func (t *templateExecHelper) GetFunc(tmpl texttemplate.Preparer, name string) (reflect.Value, bool) {
@@ -91,14 +92,15 @@ func (t *templateExecHelper) GetMapValue(tmpl texttemplate.Preparer, receiver, k
}
func (t *templateExecHelper) GetMethod(tmpl texttemplate.Preparer, receiver reflect.Value, name string) (method reflect.Value, firstArg reflect.Value) {
- // This is a hot path and receiver.MethodByName really shows up in the benchmarks.
- // Page.Render is the only method with a WithTemplateInfo as of now, so let's just
- // check that for now.
- // TODO(bep) find a more flexible, but still fast, way.
- if name == "Render" {
- if info, ok := tmpl.(tpl.Info); ok {
- if m := receiver.MethodByName(name + "WithTemplateInfo"); m.IsValid() {
- return m, reflect.ValueOf(info)
+ if t.running {
+ // This is a hot path and receiver.MethodByName really shows up in the benchmarks,
+ // so we maintain a list of method names with that signature.
+ switch name {
+ case "GetPage", "Render":
+ if info, ok := tmpl.(tpl.Info); ok {
+ if m := receiver.MethodByName(name + "WithTemplateInfo"); m.IsValid() {
+ return m, reflect.ValueOf(info)
+ }
}
}
}
@@ -133,7 +135,8 @@ func newTemplateExecuter(d *deps.Deps) (texttemplate.Executer, map[string]reflec
}
exeHelper := &templateExecHelper{
- funcs: funcsv,
+ running: d.Running,
+ funcs: funcsv,
}
return texttemplate.NewExecuter(