summaryrefslogtreecommitdiff
path: root/srv/src/http/tpl.go
diff options
context:
space:
mode:
Diffstat (limited to 'srv/src/http/tpl.go')
-rw-r--r--srv/src/http/tpl.go36
1 files changed, 8 insertions, 28 deletions
diff --git a/srv/src/http/tpl.go b/srv/src/http/tpl.go
index 2e22370..5c235a1 100644
--- a/srv/src/http/tpl.go
+++ b/srv/src/http/tpl.go
@@ -1,7 +1,6 @@
package http
import (
- "bytes"
"embed"
"fmt"
"html/template"
@@ -59,11 +58,8 @@ func (a *api) assetsURL(abs bool) string {
return a.blogURL("assets", abs)
}
-func (a *api) parseTpl(name, tplBody string) (*template.Template, error) {
-
- tpl := template.New("root")
-
- tpl = tpl.Funcs(template.FuncMap{
+func (a *api) tplFuncs() template.FuncMap {
+ return template.FuncMap{
"BlogURL": func(path string) string {
return a.blogURL(path, false)
},
@@ -81,33 +77,17 @@ func (a *api) parseTpl(name, tplBody string) (*template.Template, error) {
"DateTimeFormat": func(t time.Time) string {
return t.Format("2006-01-02")
},
- })
-
- tpl = template.Must(tpl.New("image.html").Parse(mustReadTplFile("image.html")))
-
- tpl = tpl.Funcs(template.FuncMap{
- "Image": func(id string) (template.HTML, error) {
-
- tplPayload := struct {
- ID string
- Resizable bool
- }{
- ID: id,
- Resizable: isImgResizable(id),
- }
+ }
+}
- buf := new(bytes.Buffer)
- if err := tpl.ExecuteTemplate(buf, "image.html", tplPayload); err != nil {
- return "", err
- }
+func (a *api) parseTpl(name, tplBody string) (*template.Template, error) {
- return template.HTML(buf.Bytes()), nil
- },
- })
+ tpl := template.New(name)
+ tpl = tpl.Funcs(a.tplFuncs())
var err error
- if tpl, err = tpl.New(name).Parse(tplBody); err != nil {
+ if tpl, err = tpl.Parse(tplBody); err != nil {
return nil, err
}