bookmarks.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package widget
  2. import (
  3. "html/template"
  4. "github.com/glanceapp/glance/internal/assets"
  5. )
  6. type Bookmarks struct {
  7. widgetBase `yaml:",inline"`
  8. cachedHTML template.HTML `yaml:"-"`
  9. Groups []struct {
  10. Title string `yaml:"title"`
  11. Color *HSLColorField `yaml:"color"`
  12. Links []struct {
  13. Title string `yaml:"title"`
  14. URL string `yaml:"url"`
  15. Icon string `yaml:"icon"`
  16. IsSimpleIcon bool `yaml:"-"`
  17. SameTab bool `yaml:"same-tab"`
  18. HideArrow bool `yaml:"hide-arrow"`
  19. } `yaml:"links"`
  20. } `yaml:"groups"`
  21. Style string `yaml:"style"`
  22. }
  23. func (widget *Bookmarks) Initialize() error {
  24. widget.withTitle("Bookmarks").withError(nil)
  25. for g := range widget.Groups {
  26. for l := range widget.Groups[g].Links {
  27. if widget.Groups[g].Links[l].Icon == "" {
  28. continue
  29. }
  30. link := &widget.Groups[g].Links[l]
  31. link.Icon, link.IsSimpleIcon = toSimpleIconIfPrefixed(link.Icon)
  32. }
  33. }
  34. widget.cachedHTML = widget.render(widget, assets.BookmarksTemplate)
  35. return nil
  36. }
  37. func (widget *Bookmarks) Render() template.HTML {
  38. return widget.cachedHTML
  39. }