Files
glance/internal/widget/bookmarks.go
2Q2C0DE d0c4e9d846 Add Dashboard Icons prefix support
- defined new type IconSource and constants, presently supporting:
  - LocalFile
  - SimpleIcon
  - DashboardIcon
- added new field to bookmarks and monitors to hold IconSource
- adjusted IsSimpleIcon to get truthiness from IconSource field
- generalised `toSimpleIconIfPrefixed` into `toRemoteResourceIconIfPrefixed`,
  adding support for `walkxcode`'s dashboard icons via CDN (svg)
2024-11-14 18:30:41 +11:00

50 lines
1.2 KiB
Go

package widget
import (
"html/template"
"github.com/glanceapp/glance/internal/assets"
)
type Bookmarks struct {
widgetBase `yaml:",inline"`
cachedHTML template.HTML `yaml:"-"`
Groups []struct {
Title string `yaml:"title"`
Color *HSLColorField `yaml:"color"`
Links []struct {
Title string `yaml:"title"`
URL string `yaml:"url"`
Icon string `yaml:"icon"`
IsSimpleIcon bool `yaml:"-"`
IconSource IconSource `yaml:"-"`
SameTab bool `yaml:"same-tab"`
HideArrow bool `yaml:"hide-arrow"`
} `yaml:"links"`
} `yaml:"groups"`
}
func (widget *Bookmarks) Initialize() error {
widget.withTitle("Bookmarks").withError(nil)
for g := range widget.Groups {
for l := range widget.Groups[g].Links {
if widget.Groups[g].Links[l].Icon == "" {
continue
}
link := &widget.Groups[g].Links[l]
link.Icon, link.IconSource = toRemoteResourceIconIfPrefixed(link.Icon)
link.IsSimpleIcon = link.IconSource == SimpleIcon
}
}
widget.cachedHTML = widget.render(widget, assets.BookmarksTemplate)
return nil
}
func (widget *Bookmarks) Render() template.HTML {
return widget.cachedHTML
}