Skip to content

A self-hosted dashboard that puts all your feeds in one place

Make converting string to simple icon url reusable

Svilen Markovb63b5eb262f8
diff --git a/internal/widget/bookmarks.go b/internal/widget/bookmarks.go
index 0863d98..2126b5e 100644
--- a/internal/widget/bookmarks.go
+++ b/internal/widget/bookmarks.go
@@ -2,7 +2,6 @@ package widget
import (
"html/template"
- "strings"
"github.com/glanceapp/glance/internal/assets"
)
@@ -34,11 +33,8 @@ func (widget *Bookmarks) Initialize() error {
continue
}
- if strings.HasPrefix(widget.Groups[g].Links[l].Icon, "si:") {
- icon := strings.TrimPrefix(widget.Groups[g].Links[l].Icon, "si:")
- widget.Groups[g].Links[l].IsSimpleIcon = true
- widget.Groups[g].Links[l].Icon = "https://cdnjs.cloudflare.com/ajax/libs/simple-icons/11.14.0/" + icon + ".svg"
- }
+ link := &widget.Groups[g].Links[l]
+ link.Icon, link.IsSimpleIcon = toSimpleIconIfPrefixed(link.Icon)
}
}
diff --git a/internal/widget/fields.go b/internal/widget/fields.go
index eecb916..cbbfce2 100644
--- a/internal/widget/fields.go
+++ b/internal/widget/fields.go
@@ -6,6 +6,7 @@ import (
"os"
"regexp"
"strconv"
+ "strings"
"time"
"gopkg.in/yaml.v3"
@@ -150,3 +151,14 @@ func (f *OptionalEnvString) UnmarshalYAML(node *yaml.Node) error {
return nil
}
+
+func toSimpleIconIfPrefixed(icon string) (string, bool) {
+ if !strings.HasPrefix(icon, "si:") {
+ return icon, false
+ }
+
+ icon = strings.TrimPrefix(icon, "si:")
+ icon = "https://cdnjs.cloudflare.com/ajax/libs/simple-icons/11.14.0/" + icon + ".svg"
+
+ return icon, true
+}