From 90254b92d2d2dc1e2d2e1305c0e1096bbfdeda80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=ADtalo=20Silva?= Date: Sat, 12 Apr 2025 19:48:09 -0300 Subject: [PATCH 1/2] Support embed icons on bookmarks URLs --- internal/glance/templates.go | 2 ++ internal/glance/templates/bookmarks.html | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/glance/templates.go b/internal/glance/templates.go index 699772d..8164eb0 100644 --- a/internal/glance/templates.go +++ b/internal/glance/templates.go @@ -5,6 +5,7 @@ import ( "html/template" "math" "strconv" + "strings" "golang.org/x/text/language" "golang.org/x/text/message" @@ -53,6 +54,7 @@ var globalTemplateFunctions = template.FuncMap{ return template.HTML(value + ` ` + label + ``) }, + "hasPrefix": strings.HasPrefix, } func mustParseTemplate(primary string, dependencies ...string) *template.Template { diff --git a/internal/glance/templates/bookmarks.html b/internal/glance/templates/bookmarks.html index 1952cdb..1db21c0 100644 --- a/internal/glance/templates/bookmarks.html +++ b/internal/glance/templates/bookmarks.html @@ -13,7 +13,7 @@
{{- if ne "" .Icon.URL }}
- +
{{- end }} {{ .Title }} From e11ce5d3d05fe5f46f0c98236f7fd9cc8d948d96 Mon Sep 17 00:00:00 2001 From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com> Date: Tue, 15 Apr 2025 21:55:55 +0100 Subject: [PATCH 2/2] Change the type of the field --- internal/glance/config-fields.go | 13 +++++++------ internal/glance/templates/bookmarks.html | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/internal/glance/config-fields.go b/internal/glance/config-fields.go index e2ece3f..cd244e5 100644 --- a/internal/glance/config-fields.go +++ b/internal/glance/config-fields.go @@ -3,6 +3,7 @@ package glance import ( "crypto/tls" "fmt" + "html/template" "net/http" "net/url" "regexp" @@ -115,7 +116,7 @@ func (d *durationField) UnmarshalYAML(node *yaml.Node) error { } type customIconField struct { - URL string + URL template.URL IsFlatIcon bool // TODO: along with whether the icon is flat, we also need to know // whether the icon is black or white by default in order to properly @@ -127,13 +128,13 @@ func newCustomIconField(value string) customIconField { prefix, icon, found := strings.Cut(value, ":") if !found { - field.URL = value + field.URL = template.URL(value) return field } switch prefix { case "si": - field.URL = "https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/" + icon + ".svg" + field.URL = template.URL("https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/" + icon + ".svg") field.IsFlatIcon = true case "di", "sh": // syntax: di:[.svg|.png] @@ -152,12 +153,12 @@ func newCustomIconField(value string) customIconField { } if prefix == "di" { - field.URL = "https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/" + ext + "/" + basename + "." + ext + field.URL = template.URL("https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/" + ext + "/" + basename + "." + ext) } else { - field.URL = "https://cdn.jsdelivr.net/gh/selfhst/icons/" + ext + "/" + basename + "." + ext + field.URL = template.URL("https://cdn.jsdelivr.net/gh/selfhst/icons/" + ext + "/" + basename + "." + ext) } default: - field.URL = value + field.URL = template.URL(value) } return field diff --git a/internal/glance/templates/bookmarks.html b/internal/glance/templates/bookmarks.html index 1db21c0..1952cdb 100644 --- a/internal/glance/templates/bookmarks.html +++ b/internal/glance/templates/bookmarks.html @@ -13,7 +13,7 @@
{{- if ne "" .Icon.URL }}
- +
{{- end }} {{ .Title }}