From: Bjørn Erik Pedersen Date: Tue, 31 Jul 2018 09:27:50 +0000 (+0200) Subject: tpl/partials: Remove superflous loop X-Git-Tag: v0.46~10 X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=0afa2897a0cf90f4348929ef432202efddc183a0;p=brevno-suite%2Fhugo tpl/partials: Remove superflous loop No need to check the themes template prefix. --- diff --git a/tpl/partials/partials.go b/tpl/partials/partials.go index 26632972..dba0e501 100644 --- a/tpl/partials/partials.go +++ b/tpl/partials/partials.go @@ -74,36 +74,35 @@ func (ns *Namespace) Include(name string, contextList ...interface{}) (interface context = contextList[0] } - for _, n := range []string{"partials/" + name, "theme/partials/" + name} { - templ, found := ns.deps.Tmpl.Lookup(n) + n := "partials/" + name + templ, found := ns.deps.Tmpl.Lookup(n) - if !found { - // For legacy reasons. - templ, found = ns.deps.Tmpl.Lookup(n + ".html") - } - if found { - b := bp.GetBuffer() - defer bp.PutBuffer(b) - - if err := templ.Execute(b, context); err != nil { - return "", err - } + if !found { + // For legacy reasons. + templ, found = ns.deps.Tmpl.Lookup(n + ".html") + } + if found { + b := bp.GetBuffer() + defer bp.PutBuffer(b) - if _, ok := templ.(*texttemplate.Template); ok { - s := b.String() - if ns.deps.Metrics != nil { - ns.deps.Metrics.TrackValue(n, s) - } - return s, nil - } + if err := templ.Execute(b, context); err != nil { + return "", err + } + if _, ok := templ.(*texttemplate.Template); ok { s := b.String() if ns.deps.Metrics != nil { ns.deps.Metrics.TrackValue(n, s) } - return template.HTML(s), nil + return s, nil + } + s := b.String() + if ns.deps.Metrics != nil { + ns.deps.Metrics.TrackValue(n, s) } + return template.HTML(s), nil + } return "", fmt.Errorf("Partial %q not found", name)