diff --git a/main.go b/main.go index ef5d106..2743737 100644 --- a/main.go +++ b/main.go @@ -39,7 +39,7 @@ func main() { ) defer Database.Close() - if tmpl, err := template.New("homepage").ParseFS(TemplateFS, "templates/*"); err == nil { + if tmpl, err := template.New("homepage").Funcs(tmplFuncs).ParseFS(TemplateFS, "templates/*"); err == nil { Templates = tmpl } else { panic(err) diff --git a/templates/bookmark.html b/templates/bookmark.html index 03fd5f2..6eb41e2 100644 --- a/templates/bookmark.html +++ b/templates/bookmark.html @@ -1,3 +1,3 @@ -
+
diff --git a/utils.go b/utils.go index 999b2ac..c9d7de1 100644 --- a/utils.go +++ b/utils.go @@ -3,6 +3,7 @@ package main import ( crand "crypto/rand" "encoding/hex" + "html/template" "net/http" "time" ) @@ -84,3 +85,24 @@ func makeNewSession(w http.ResponseWriter) (*Session, error) { return session, nil } + +var tmplFuncs = template.FuncMap{ + "js": func(s string) template.JS { + return template.JS(s) + }, + "jss": func(s string) template.JSStr { + return template.JSStr(s) + }, + "css": func(s string) template.CSS { + return template.CSS(s) + }, + "attr": func(s string) template.HTMLAttr { + return template.HTMLAttr(s) + }, + "safe": func(s string) template.HTML { + return template.HTML(s) + }, + "url": func(s string) template.URL { + return template.URL(s) + }, +}