diff --git a/modules/bluemonday/bluemonday.go b/modules/bluemonday/bluemonday.go new file mode 100644 index 0000000..d00f957 --- /dev/null +++ b/modules/bluemonday/bluemonday.go @@ -0,0 +1,5 @@ +package bluemonday + +import "github.com/microcosm-cc/bluemonday" + +var Policy = bluemonday.UGCPolicy() diff --git a/modules/template/funcmap.go b/modules/funcmap/funcmap.go similarity index 78% rename from modules/template/funcmap.go rename to modules/funcmap/funcmap.go index 7cfd048..6b0d91a 100644 --- a/modules/template/funcmap.go +++ b/modules/funcmap/funcmap.go @@ -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("") }, "htmlSafe": func(html string) template.HTML { return template.HTML( //nolint:gosec - bluemondayPolicy.Sanitize(html), + modbluemonday.Policy.Sanitize(html), ) }, "pageIs": func(want, got string) bool { diff --git a/modules/template/template.go b/modules/template/template.go index cb04af8..121a1fa 100644 --- a/modules/template/template.go +++ b/modules/template/template.go @@ -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" ) @@ -17,9 +17,8 @@ type tplMap map[string]*template.Template var ( templateMap tplMap // embedded templates. - tmplFS fs.FS - bluemondayPolicy = bluemonday.UGCPolicy() - setting *settings.Settings + tmplFS fs.FS + setting *settings.Settings // global logger. slogger *slogging.Slogger // local logger copy. @@ -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))) }