glance/internal/widget/bookmarks.go

52 lines
1.3 KiB
Go
Raw Normal View History

2024-04-27 21:10:24 +02:00
package widget
import (
"html/template"
"strings"
2024-04-27 21:10:24 +02:00
"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:"-"`
SameTab bool `yaml:"same-tab"`
HideArrow bool `yaml:"hide-arrow"`
2024-04-27 21:10:24 +02:00
} `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
}
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"
}
}
}
2024-04-27 21:10:24 +02:00
widget.cachedHTML = widget.render(widget, assets.BookmarksTemplate)
return nil
}
func (widget *Bookmarks) Render() template.HTML {
return widget.cachedHTML
}