mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-21 18:31:24 +02:00
Update icons implementation to use custom type
This commit is contained in:
parent
d656986413
commit
f7239137d6
@ -1059,7 +1059,7 @@ details[open] .summary::after {
|
|||||||
opacity: 0.8;
|
opacity: 0.8;
|
||||||
}
|
}
|
||||||
|
|
||||||
:root:not(.light-scheme) .simple-icon {
|
:root:not(.light-scheme) .flat-icon {
|
||||||
filter: invert(1);
|
filter: invert(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1355,7 +1355,7 @@ details[open] .summary::after {
|
|||||||
transition: filter 0.3s, opacity 0.3s;
|
transition: filter 0.3s, opacity 0.3s;
|
||||||
}
|
}
|
||||||
|
|
||||||
.monitor-site-icon.simple-icon {
|
.monitor-site-icon.flat-icon {
|
||||||
opacity: 0.7;
|
opacity: 0.7;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1363,7 +1363,7 @@ details[open] .summary::after {
|
|||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.monitor-site:hover .monitor-site-icon:not(.simple-icon) {
|
.monitor-site:hover .monitor-site-icon:not(.flat-icon) {
|
||||||
filter: grayscale(0);
|
filter: grayscale(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,9 +8,9 @@
|
|||||||
<ul class="list list-gap-2">
|
<ul class="list list-gap-2">
|
||||||
{{ range .Links }}
|
{{ range .Links }}
|
||||||
<li class="flex items-center gap-10">
|
<li class="flex items-center gap-10">
|
||||||
{{ if ne "" .Icon }}
|
{{ if ne "" .Icon.URL }}
|
||||||
<div class="bookmarks-icon-container">
|
<div class="bookmarks-icon-container">
|
||||||
<img class="bookmarks-icon{{ if .IsSimpleIcon }} simple-icon{{ end }}" src="{{ .Icon }}" alt="" loading="lazy">
|
<img class="bookmarks-icon{{ if .Icon.IsFlatIcon }} flat-icon{{ end }}" src="{{ .Icon.URL }}" alt="" loading="lazy">
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<a href="{{ .URL }}" class="bookmarks-link {{ if .HideArrow }}bookmarks-link-no-arrow {{ end }}color-highlight size-h4" {{ if not .SameTab }}target="_blank"{{ end }} rel="noreferrer">{{ .Title }}</a>
|
<a href="{{ .URL }}" class="bookmarks-link {{ if .HideArrow }}bookmarks-link-no-arrow {{ end }}color-highlight size-h4" {{ if not .SameTab }}target="_blank"{{ end }} rel="noreferrer">{{ .Title }}</a>
|
||||||
|
@ -21,8 +21,8 @@
|
|||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{ define "site" }}
|
{{ define "site" }}
|
||||||
{{ if .IconUrl }}
|
{{ if .Icon.URL }}
|
||||||
<img class="monitor-site-icon{{ if .IsSimpleIcon }} simple-icon{{ end }}" src="{{ .IconUrl }}" alt="" loading="lazy">
|
<img class="monitor-site-icon{{ if .Icon.IsFlatIcon }} flat-icon{{ end }}" src="{{ .Icon.URL }}" alt="" loading="lazy">
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<div class="min-width-0">
|
<div class="min-width-0">
|
||||||
<a class="size-h3 color-highlight text-truncate block" href="{{ .URL }}" {{ if not .SameTab }}target="_blank"{{ end }} rel="noreferrer">{{ .Title }}</a>
|
<a class="size-h3 color-highlight text-truncate block" href="{{ .URL }}" {{ if not .SameTab }}target="_blank"{{ end }} rel="noreferrer">{{ .Title }}</a>
|
||||||
|
@ -13,32 +13,17 @@ type Bookmarks struct {
|
|||||||
Title string `yaml:"title"`
|
Title string `yaml:"title"`
|
||||||
Color *HSLColorField `yaml:"color"`
|
Color *HSLColorField `yaml:"color"`
|
||||||
Links []struct {
|
Links []struct {
|
||||||
Title string `yaml:"title"`
|
Title string `yaml:"title"`
|
||||||
URL string `yaml:"url"`
|
URL string `yaml:"url"`
|
||||||
Icon string `yaml:"icon"`
|
Icon CustomIcon `yaml:"icon"`
|
||||||
IsSimpleIcon bool `yaml:"-"`
|
SameTab bool `yaml:"same-tab"`
|
||||||
IconSource IconSource `yaml:"-"`
|
HideArrow bool `yaml:"hide-arrow"`
|
||||||
SameTab bool `yaml:"same-tab"`
|
|
||||||
HideArrow bool `yaml:"hide-arrow"`
|
|
||||||
} `yaml:"links"`
|
} `yaml:"links"`
|
||||||
} `yaml:"groups"`
|
} `yaml:"groups"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Bookmarks) Initialize() error {
|
func (widget *Bookmarks) Initialize() error {
|
||||||
widget.withTitle("Bookmarks").withError(nil)
|
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 = toIconURIIfPrefixed(link.Icon)
|
|
||||||
link.IsSimpleIcon = link.IconSource == SimpleIcon
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
widget.cachedHTML = widget.render(widget, assets.BookmarksTemplate)
|
widget.cachedHTML = widget.render(widget, assets.BookmarksTemplate)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -27,14 +27,6 @@ type HSLColorField struct {
|
|||||||
Lightness uint8
|
Lightness uint8
|
||||||
}
|
}
|
||||||
|
|
||||||
type IconSource uint8
|
|
||||||
|
|
||||||
const (
|
|
||||||
IconURI IconSource = iota
|
|
||||||
SimpleIcon
|
|
||||||
DashboardIcon
|
|
||||||
)
|
|
||||||
|
|
||||||
func (c *HSLColorField) String() string {
|
func (c *HSLColorField) String() string {
|
||||||
return fmt.Sprintf("hsl(%d, %d%%, %d%%)", c.Hue, c.Saturation, c.Lightness)
|
return fmt.Sprintf("hsl(%d, %d%%, %d%%)", c.Hue, c.Saturation, c.Lightness)
|
||||||
}
|
}
|
||||||
@ -164,38 +156,49 @@ func (f *OptionalEnvString) String() string {
|
|||||||
return string(*f)
|
return string(*f)
|
||||||
}
|
}
|
||||||
|
|
||||||
func toIconURIIfPrefixed(icon string) (string, IconSource) {
|
type CustomIcon struct {
|
||||||
var prefix, iconstr string
|
URL string
|
||||||
|
IsFlatIcon bool
|
||||||
|
// TODO: along with whether the icon is flat, we also need to know
|
||||||
|
// whether the icon is black or white by default in order to properly
|
||||||
|
// invert the color based on the theme being light or dark
|
||||||
|
}
|
||||||
|
|
||||||
prefix, iconstr, found := strings.Cut(icon, ":")
|
func (i *CustomIcon) UnmarshalYAML(node *yaml.Node) error {
|
||||||
|
var value string
|
||||||
|
if err := node.Decode(&value); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
prefix, icon, found := strings.Cut(value, ":")
|
||||||
if !found {
|
if !found {
|
||||||
return icon, IconURI
|
i.URL = value
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// syntax: si:<icon_name>
|
switch prefix {
|
||||||
if prefix == "si" {
|
case "si":
|
||||||
icon = "https://cdnjs.cloudflare.com/ajax/libs/simple-icons/11.14.0/" + iconstr + ".svg"
|
i.URL = "https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/" + icon + ".svg"
|
||||||
return icon, SimpleIcon
|
i.IsFlatIcon = true
|
||||||
}
|
case "di":
|
||||||
|
// syntax: di:<icon_name>[.svg|.png]
|
||||||
// syntax: di:<icon_name>[.svg|.png]
|
|
||||||
if prefix == "di" {
|
|
||||||
// if the icon name is specified without extension, it is assumed to be wanting the SVG icon
|
// if the icon name is specified without extension, it is assumed to be wanting the SVG icon
|
||||||
// otherwise, specify the extension of either .svg or .png to use either of the CDN offerings
|
// otherwise, specify the extension of either .svg or .png to use either of the CDN offerings
|
||||||
// any other extension will be interpreted as .svg
|
// any other extension will be interpreted as .svg
|
||||||
var basename, ext string
|
basename, ext, found := strings.Cut(icon, ".")
|
||||||
|
|
||||||
basename, ext, found := strings.Cut(iconstr, ".")
|
|
||||||
|
|
||||||
if !found {
|
if !found {
|
||||||
ext = "svg"
|
ext = "svg"
|
||||||
basename = iconstr
|
basename = icon
|
||||||
}
|
}
|
||||||
|
|
||||||
icon = "https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons@master/" + ext + "/" + basename + "." + ext
|
if ext != "svg" && ext != "png" {
|
||||||
return icon, DashboardIcon
|
ext = "svg"
|
||||||
|
}
|
||||||
|
|
||||||
|
i.URL = "https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons@master/" + ext + "/" + basename + "." + ext
|
||||||
|
default:
|
||||||
|
i.URL = value
|
||||||
}
|
}
|
||||||
|
|
||||||
return icon, IconURI
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -47,9 +47,7 @@ type Monitor struct {
|
|||||||
*feed.SiteStatusRequest `yaml:",inline"`
|
*feed.SiteStatusRequest `yaml:",inline"`
|
||||||
Status *feed.SiteStatus `yaml:"-"`
|
Status *feed.SiteStatus `yaml:"-"`
|
||||||
Title string `yaml:"title"`
|
Title string `yaml:"title"`
|
||||||
IconUrl string `yaml:"icon"`
|
Icon CustomIcon `yaml:"icon"`
|
||||||
IsSimpleIcon bool `yaml:"-"`
|
|
||||||
IconSource IconSource `yaml:"-"`
|
|
||||||
SameTab bool `yaml:"same-tab"`
|
SameTab bool `yaml:"same-tab"`
|
||||||
StatusText string `yaml:"-"`
|
StatusText string `yaml:"-"`
|
||||||
StatusStyle string `yaml:"-"`
|
StatusStyle string `yaml:"-"`
|
||||||
@ -61,11 +59,6 @@ type Monitor struct {
|
|||||||
func (widget *Monitor) Initialize() error {
|
func (widget *Monitor) Initialize() error {
|
||||||
widget.withTitle("Monitor").withCacheDuration(5 * time.Minute)
|
widget.withTitle("Monitor").withCacheDuration(5 * time.Minute)
|
||||||
|
|
||||||
for i := range widget.Sites {
|
|
||||||
widget.Sites[i].IconUrl, widget.Sites[i].IconSource = toIconURIIfPrefixed(widget.Sites[i].IconUrl)
|
|
||||||
widget.Sites[i].IsSimpleIcon = widget.Sites[i].IconSource == SimpleIcon
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user