Skip to content

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

Add DashboardIcon (PNG) Support - Refactored to make better naming sense - Added capability to select between the PNG and SVG offerings of DashboardIcons

Doc Emd6569864134c
diff --git a/internal/widget/bookmarks.go b/internal/widget/bookmarks.go
index 1ad3390..b200610 100644
--- a/internal/widget/bookmarks.go
+++ b/internal/widget/bookmarks.go
@@ -34,7 +34,7 @@ func (widget *Bookmarks) Initialize() error {
}
link := &widget.Groups[g].Links[l]
- link.Icon, link.IconSource = toRemoteResourceIconIfPrefixed(link.Icon)
+ link.Icon, link.IconSource = toIconURIIfPrefixed(link.Icon)
link.IsSimpleIcon = link.IconSource == SimpleIcon
}
}
diff --git a/internal/widget/fields.go b/internal/widget/fields.go
index 51f7d92..ca6659a 100644
--- a/internal/widget/fields.go
+++ b/internal/widget/fields.go
@@ -30,7 +30,7 @@ type HSLColorField struct {
type IconSource uint8
const (
- LocalFile IconSource = iota
+ IconURI IconSource = iota
SimpleIcon
DashboardIcon
)
@@ -164,24 +164,38 @@ func (f *OptionalEnvString) String() string {
return string(*f)
}
-func toRemoteResourceIconIfPrefixed(icon string) (string, IconSource) {
+func toIconURIIfPrefixed(icon string) (string, IconSource) {
var prefix, iconstr string
prefix, iconstr, found := strings.Cut(icon, ":")
if !found {
- return icon, LocalFile
+ return icon, IconURI
}
+ // syntax: si:<icon_name>
if prefix == "si" {
icon = "https://cdnjs.cloudflare.com/ajax/libs/simple-icons/11.14.0/" + iconstr + ".svg"
return icon, SimpleIcon
}
+ // syntax: di:<icon_name>[.svg|.png]
if prefix == "di" {
- icon = "https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons@master/svg/" + iconstr + ".svg"
+ // if the icon name is specified without extension, it is assumed to be wanting the SVG icon
+ // otherwise, specify the extension of either .svg or .png to use either of the CDN offerings
+ // any other extension will be interpreted as .svg
+ var basename, ext string
+
+ basename, ext, found := strings.Cut(iconstr, ".")
+
+ if !found {
+ ext = "svg"
+ basename = iconstr
+ }
+
+ icon = "https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons@master/" + ext + "/" + basename + "." + ext
return icon, DashboardIcon
}
- return icon, LocalFile
+ return icon, IconURI
}
diff --git a/internal/widget/monitor.go b/internal/widget/monitor.go
index 5ad4e20..96715ec 100644
--- a/internal/widget/monitor.go
+++ b/internal/widget/monitor.go
@@ -62,7 +62,7 @@ func (widget *Monitor) Initialize() error {
widget.withTitle("Monitor").withCacheDuration(5 * time.Minute)
for i := range widget.Sites {
- widget.Sites[i].IconUrl, widget.Sites[i].IconSource = toRemoteResourceIconIfPrefixed(widget.Sites[i].IconUrl)
+ widget.Sites[i].IconUrl, widget.Sites[i].IconSource = toIconURIIfPrefixed(widget.Sites[i].IconUrl)
widget.Sites[i].IsSimpleIcon = widget.Sites[i].IconSource == SimpleIcon
}