go: create funcmap,bluemonday modules
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
leo 2023-05-11 18:16:15 +02:00
parent 1fb7479d8e
commit adeb6f5720
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ
3 changed files with 18 additions and 10 deletions

@ -0,0 +1,5 @@
package bluemonday
import "github.com/microcosm-cc/bluemonday"
var Policy = bluemonday.UGCPolicy()

@ -1,6 +1,10 @@
package template
package funcmap
import "html/template"
import (
"html/template"
modbluemonday "git.dotya.ml/mirre-mt/pcmt/modules/bluemonday"
)
func FuncMap() template.FuncMap {
return template.FuncMap{
@ -8,7 +12,7 @@ func FuncMap() template.FuncMap {
"endifIE": func() template.HTML { return template.HTML("<![endif]>") },
"htmlSafe": func(html string) template.HTML {
return template.HTML( //nolint:gosec
bluemondayPolicy.Sanitize(html),
modbluemonday.Policy.Sanitize(html),
)
},
"pageIs": func(want, got string) bool {

@ -7,8 +7,8 @@ import (
"strings"
"git.dotya.ml/mirre-mt/pcmt/app/settings"
"git.dotya.ml/mirre-mt/pcmt/modules/funcmap"
"git.dotya.ml/mirre-mt/pcmt/slogging"
"github.com/microcosm-cc/bluemonday"
"golang.org/x/exp/slog"
)
@ -18,7 +18,6 @@ var (
templateMap tplMap
// embedded templates.
tmplFS fs.FS
bluemondayPolicy = bluemonday.UGCPolicy()
setting *settings.Settings
// global logger.
slogger *slogging.Slogger
@ -68,7 +67,7 @@ func Get(name string) *template.Template {
allTmpls[i] = strings.TrimPrefix(v, tmplPath+"/")
t = t.New(allTmpls[i]).Funcs(FuncMap())
t = t.New(allTmpls[i]).Funcs(funcmap.FuncMap())
template.Must(t.Parse(string(rawfile)))
}
@ -99,7 +98,7 @@ func initTemplates(f fs.FS) {
allTmpls[i] = strings.TrimPrefix(v, "templates/")
t := Renderer.tmpls.New(allTmpls[i]).Funcs(FuncMap())
t := Renderer.tmpls.New(allTmpls[i]).Funcs(funcmap.FuncMap())
template.Must(t.Parse(string(rawfile)))
}
@ -112,7 +111,7 @@ func initTemplates(f fs.FS) {
}
allTmpls[i] = strings.TrimPrefix(v, tmplPath+"/")
t = Renderer.tmpls.New(allTmpls[i]).Funcs(FuncMap())
t = Renderer.tmpls.New(allTmpls[i]).Funcs(funcmap.FuncMap())
template.Must(t.Parse(string(rawfile)))
}