2024-04-27 21:10:24 +02:00
|
|
|
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 {
|
2024-05-03 06:38:40 +02:00
|
|
|
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"`
|
2024-05-12 23:07:58 +02:00
|
|
|
Style string `yaml:"style"`
|
2024-04-27 21:10:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (widget *Bookmarks) Initialize() error {
|
|
|
|
widget.withTitle("Bookmarks").withError(nil)
|
2024-05-03 06:38:40 +02:00
|
|
|
|
|
|
|
for g := range widget.Groups {
|
|
|
|
for l := range widget.Groups[g].Links {
|
|
|
|
if widget.Groups[g].Links[l].Icon == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2024-05-30 23:08:33 +02:00
|
|
|
link := &widget.Groups[g].Links[l]
|
|
|
|
link.Icon, link.IsSimpleIcon = toSimpleIconIfPrefixed(link.Icon)
|
2024-05-03 06:38:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|