fixed bugs

This commit is contained in:
Timon Ringwald 2022-09-06 12:00:43 +02:00
parent 49b32ab4d9
commit 51f56c14a1
3 changed files with 24 additions and 2 deletions

View File

@ -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)

View File

@ -1,3 +1,3 @@
<a href="{{ .Link }}" class="bookmark" style='background-color: {{ .GetColor }}; {{ if not .HideBorder }} box-shadow: 0px 0px 3px black; {{ end }}; {{ if not (eq .IconPadding "") }} padding: {{ .IconPadding }}; {{ end }}'>
<div class="background" style='background-image: url("{{ .Image }}"); background-size: {{ .GetImageSize }}'></div>
<div class="background" style='background-image: url("{{ .Image | url }}"); background-size: {{ .GetImageSize }}'></div>
</a>

View File

@ -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)
},
}