|
|
|
@ -1,42 +1,52 @@
|
|
|
|
package glance
|
|
|
|
package glance
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
|
|
|
|
"errors"
|
|
|
|
"html/template"
|
|
|
|
"html/template"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
var bookmarksWidgetTemplate = mustParseTemplate("bookmarks.html", "widget-base.html")
|
|
|
|
var bookmarksWidgetTemplate = mustParseTemplate("bookmarks.html", "widget-base.html")
|
|
|
|
|
|
|
|
var bookmarksGridWidgetTemplate = mustParseTemplate("bookmarks-grid.html", "widget-base.html")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type bookmarkLinks []struct {
|
|
|
|
|
|
|
|
Title string `yaml:"title"`
|
|
|
|
|
|
|
|
URL string `yaml:"url"`
|
|
|
|
|
|
|
|
Description string `yaml:"description"`
|
|
|
|
|
|
|
|
Icon customIconField `yaml:"icon"`
|
|
|
|
|
|
|
|
// we need a pointer to bool to know whether a value was provided,
|
|
|
|
|
|
|
|
// however there's no way to dereference a pointer in a template so
|
|
|
|
|
|
|
|
// {{ if not .SameTab }} would return true for any non-nil pointer
|
|
|
|
|
|
|
|
// which leaves us with no way of checking if the value is true or
|
|
|
|
|
|
|
|
// false, hence the duplicated fields below
|
|
|
|
|
|
|
|
SameTabRaw *bool `yaml:"same-tab"`
|
|
|
|
|
|
|
|
SameTab bool `yaml:"-"`
|
|
|
|
|
|
|
|
HideArrowRaw *bool `yaml:"hide-arrow"`
|
|
|
|
|
|
|
|
HideArrow bool `yaml:"-"`
|
|
|
|
|
|
|
|
Target string `yaml:"target"`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type bookmarksWidget struct {
|
|
|
|
type bookmarksWidget struct {
|
|
|
|
widgetBase `yaml:",inline"`
|
|
|
|
widgetBase `yaml:",inline"`
|
|
|
|
cachedHTML template.HTML `yaml:"-"`
|
|
|
|
cachedHTML template.HTML `yaml:"-"`
|
|
|
|
|
|
|
|
Style string `yaml:"style"`
|
|
|
|
|
|
|
|
Links *bookmarkLinks `yaml:"-"`
|
|
|
|
Groups []struct {
|
|
|
|
Groups []struct {
|
|
|
|
Title string `yaml:"title"`
|
|
|
|
Title string `yaml:"title"`
|
|
|
|
Color *hslColorField `yaml:"color"`
|
|
|
|
Color *hslColorField `yaml:"color"`
|
|
|
|
SameTab bool `yaml:"same-tab"`
|
|
|
|
SameTab bool `yaml:"same-tab"`
|
|
|
|
HideArrow bool `yaml:"hide-arrow"`
|
|
|
|
HideArrow bool `yaml:"hide-arrow"`
|
|
|
|
Target string `yaml:"target"`
|
|
|
|
Target string `yaml:"target"`
|
|
|
|
Links []struct {
|
|
|
|
Links bookmarkLinks `yaml:"links"`
|
|
|
|
Title string `yaml:"title"`
|
|
|
|
|
|
|
|
URL string `yaml:"url"`
|
|
|
|
|
|
|
|
Description string `yaml:"description"`
|
|
|
|
|
|
|
|
Icon customIconField `yaml:"icon"`
|
|
|
|
|
|
|
|
// we need a pointer to bool to know whether a value was provided,
|
|
|
|
|
|
|
|
// however there's no way to dereference a pointer in a template so
|
|
|
|
|
|
|
|
// {{ if not .SameTab }} would return true for any non-nil pointer
|
|
|
|
|
|
|
|
// which leaves us with no way of checking if the value is true or
|
|
|
|
|
|
|
|
// false, hence the duplicated fields below
|
|
|
|
|
|
|
|
SameTabRaw *bool `yaml:"same-tab"`
|
|
|
|
|
|
|
|
SameTab bool `yaml:"-"`
|
|
|
|
|
|
|
|
HideArrowRaw *bool `yaml:"hide-arrow"`
|
|
|
|
|
|
|
|
HideArrow bool `yaml:"-"`
|
|
|
|
|
|
|
|
Target string `yaml:"target"`
|
|
|
|
|
|
|
|
} `yaml:"links"`
|
|
|
|
|
|
|
|
} `yaml:"groups"`
|
|
|
|
} `yaml:"groups"`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (widget *bookmarksWidget) initialize() error {
|
|
|
|
func (widget *bookmarksWidget) initialize() error {
|
|
|
|
widget.withTitle("Bookmarks").withError(nil)
|
|
|
|
widget.withTitle("Bookmarks").withError(nil)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if len(widget.Groups) == 0 {
|
|
|
|
|
|
|
|
return errors.New("must have at least one group")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for g := range widget.Groups {
|
|
|
|
for g := range widget.Groups {
|
|
|
|
group := &widget.Groups[g]
|
|
|
|
group := &widget.Groups[g]
|
|
|
|
for l := range group.Links {
|
|
|
|
for l := range group.Links {
|
|
|
|
@ -67,7 +77,16 @@ func (widget *bookmarksWidget) initialize() error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
widget.cachedHTML = widget.renderTemplate(widget, bookmarksWidgetTemplate)
|
|
|
|
if widget.Style == "grid" {
|
|
|
|
|
|
|
|
if len(widget.Groups) != 1 {
|
|
|
|
|
|
|
|
return errors.New("grid style can only be used with a single group")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
widget.Links = &widget.Groups[0].Links
|
|
|
|
|
|
|
|
widget.cachedHTML = widget.renderTemplate(widget, bookmarksGridWidgetTemplate)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
widget.cachedHTML = widget.renderTemplate(widget, bookmarksWidgetTemplate)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|