From ae1fb05607c7232280851bf53e34f977e8e99292 Mon Sep 17 00:00:00 2001 From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com> Date: Mon, 16 Dec 2024 13:58:58 +0000 Subject: [PATCH] Better convention for safe template types --- internal/glance/config-fields.go | 5 ----- internal/glance/templates.go | 6 ++++++ internal/glance/templates/bookmarks.html | 2 +- internal/glance/templates/theme-style.gotmpl | 6 +++--- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/internal/glance/config-fields.go b/internal/glance/config-fields.go index 0fefb12..9a47820 100644 --- a/internal/glance/config-fields.go +++ b/internal/glance/config-fields.go @@ -2,7 +2,6 @@ package glance import ( "fmt" - "html/template" "os" "regexp" "strconv" @@ -30,10 +29,6 @@ func (c *hslColorField) String() string { return fmt.Sprintf("hsl(%d, %d%%, %d%%)", c.Hue, c.Saturation, c.Lightness) } -func (c *hslColorField) AsCSSValue() template.CSS { - return template.CSS(c.String()) -} - func (c *hslColorField) UnmarshalYAML(node *yaml.Node) error { var value string diff --git a/internal/glance/templates.go b/internal/glance/templates.go index f3e6158..e87e714 100644 --- a/internal/glance/templates.go +++ b/internal/glance/templates.go @@ -16,6 +16,12 @@ var intl = message.NewPrinter(language.English) var globalTemplateFunctions = template.FuncMap{ "formatViewerCount": formatViewerCount, "formatNumber": intl.Sprint, + "safeCSS": func(str string) template.CSS { + return template.CSS(str) + }, + "safeURL": func(str string) template.URL { + return template.URL(str) + }, "absInt": func(i int) int { return int(math.Abs(float64(i))) }, diff --git a/internal/glance/templates/bookmarks.html b/internal/glance/templates/bookmarks.html index 25afa4d..ad9f899 100644 --- a/internal/glance/templates/bookmarks.html +++ b/internal/glance/templates/bookmarks.html @@ -3,7 +3,7 @@ {{ define "widget-content" }}