mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-21 02:18:22 +02:00
Refactor icon stuff
This commit is contained in:
parent
8f986f1403
commit
f0541ea5c8
@ -188,7 +188,7 @@ This assumes that the config you want to print is in your current working direct
|
|||||||
|
|
||||||
## Icons
|
## Icons
|
||||||
|
|
||||||
For widgets which provide you with the ability to specify icons such as the monitor, bookmarks, docker containers, etc, you can use the `icon` property to specify a URL to an image. Alternatively, you can also use icon names from multiple libraries via prefixes:
|
For widgets which provide you with the ability to specify icons such as the monitor, bookmarks, docker containers, etc, you can use the `icon` property to specify a URL to an image or use icon names from multiple libraries via prefixes:
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
icon: si:immich # si for Simple icons https://simpleicons.org/
|
icon: si:immich # si for Simple icons https://simpleicons.org/
|
||||||
|
@ -131,10 +131,7 @@ func (d *durationField) UnmarshalYAML(node *yaml.Node) error {
|
|||||||
|
|
||||||
type customIconField struct {
|
type customIconField struct {
|
||||||
URL template.URL
|
URL template.URL
|
||||||
IsFlatIcon bool
|
AutoInvert 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCustomIconField(value string) customIconField {
|
func newCustomIconField(value string) customIconField {
|
||||||
@ -142,7 +139,7 @@ func newCustomIconField(value string) customIconField {
|
|||||||
field := customIconField{}
|
field := customIconField{}
|
||||||
|
|
||||||
if strings.HasPrefix(value, autoInvertPrefix) {
|
if strings.HasPrefix(value, autoInvertPrefix) {
|
||||||
field.IsFlatIcon = true
|
field.AutoInvert = true
|
||||||
value = strings.TrimPrefix(value, autoInvertPrefix)
|
value = strings.TrimPrefix(value, autoInvertPrefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,12 +161,12 @@ func newCustomIconField(value string) customIconField {
|
|||||||
|
|
||||||
switch prefix {
|
switch prefix {
|
||||||
case "si":
|
case "si":
|
||||||
field.IsFlatIcon = true
|
field.AutoInvert = true
|
||||||
field.URL = template.URL("https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/" + basename + ".svg")
|
field.URL = template.URL("https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/" + basename + ".svg")
|
||||||
case "di":
|
case "di":
|
||||||
field.URL = template.URL("https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/" + ext + "/" + basename + "." + ext)
|
field.URL = template.URL("https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/" + ext + "/" + basename + "." + ext)
|
||||||
case "mdi":
|
case "mdi":
|
||||||
field.IsFlatIcon = true
|
field.AutoInvert = true
|
||||||
field.URL = template.URL("https://cdn.jsdelivr.net/npm/@mdi/svg@latest/svg/" + basename + ".svg")
|
field.URL = template.URL("https://cdn.jsdelivr.net/npm/@mdi/svg@latest/svg/" + basename + ".svg")
|
||||||
case "sh":
|
case "sh":
|
||||||
field.URL = template.URL("https://cdn.jsdelivr.net/gh/selfhst/icons/" + ext + "/" + basename + "." + ext)
|
field.URL = template.URL("https://cdn.jsdelivr.net/gh/selfhst/icons/" + ext + "/" + basename + "." + ext)
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
<div class="flex items-center gap-10">
|
<div class="flex items-center gap-10">
|
||||||
{{- if ne "" .Icon.URL }}
|
{{- if ne "" .Icon.URL }}
|
||||||
<div class="bookmarks-icon-container">
|
<div class="bookmarks-icon-container">
|
||||||
<img class="bookmarks-icon{{ if .Icon.IsFlatIcon }} flat-icon{{ end }}" src="{{ .Icon.URL }}" alt="" loading="lazy">
|
<img class="bookmarks-icon{{ if .Icon.AutoInvert }} flat-icon{{ end }}" src="{{ .Icon.URL }}" alt="" loading="lazy">
|
||||||
</div>
|
</div>
|
||||||
{{- end }}
|
{{- end }}
|
||||||
<a href="{{ .URL | safeURL }}" class="bookmarks-link {{ if .HideArrow }}bookmarks-link-no-arrow {{ end }}color-highlight size-h4" {{ if .Target }}target="{{ .Target }}"{{ end }} rel="noreferrer">{{ .Title }}</a>
|
<a href="{{ .URL | safeURL }}" class="bookmarks-link {{ if .HideArrow }}bookmarks-link-no-arrow {{ end }}color-highlight size-h4" {{ if .Target }}target="{{ .Target }}"{{ end }} rel="noreferrer">{{ .Title }}</a>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
{{- range .Containers }}
|
{{- range .Containers }}
|
||||||
<li class="docker-container flex items-center gap-15">
|
<li class="docker-container flex items-center gap-15">
|
||||||
<div class="shrink-0" data-popover-type="html" data-popover-position="above" data-popover-offset="0.25" data-popover-margin="0.1rem" data-popover-max-width="400px" aria-hidden="true">
|
<div class="shrink-0" data-popover-type="html" data-popover-position="above" data-popover-offset="0.25" data-popover-margin="0.1rem" data-popover-max-width="400px" aria-hidden="true">
|
||||||
<img class="docker-container-icon{{ if .Icon.IsFlatIcon }} flat-icon{{ end }}" src="{{ .Icon.URL }}" alt="" loading="lazy">
|
<img class="docker-container-icon{{ if .Icon.AutoInvert }} flat-icon{{ end }}" src="{{ .Icon.URL }}" alt="" loading="lazy">
|
||||||
<div data-popover-html>
|
<div data-popover-html>
|
||||||
<div class="color-highlight text-truncate block">{{ .Image }}</div>
|
<div class="color-highlight text-truncate block">{{ .Image }}</div>
|
||||||
<div>{{ .StateText }}</div>
|
<div>{{ .StateText }}</div>
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
{{ define "site" }}
|
{{ define "site" }}
|
||||||
{{ if .Icon.URL }}
|
{{ if .Icon.URL }}
|
||||||
<img class="monitor-site-icon{{ if .Icon.IsFlatIcon }} flat-icon{{ end }}" src="{{ .Icon.URL }}" alt="" loading="lazy">
|
<img class="monitor-site-icon{{ if .Icon.AutoInvert }} flat-icon{{ end }}" src="{{ .Icon.URL }}" alt="" loading="lazy">
|
||||||
{{ end }}
|
{{ end }}
|
||||||
<div class="grow min-width-0">
|
<div class="grow min-width-0">
|
||||||
<a class="size-h3 color-highlight text-truncate block" href="{{ .URL | safeURL }}" {{ if not .SameTab }}target="_blank"{{ end }} rel="noreferrer">{{ .Title }}</a>
|
<a class="size-h3 color-highlight text-truncate block" href="{{ .URL | safeURL }}" {{ if not .SameTab }}target="_blank"{{ end }} rel="noreferrer">{{ .Title }}</a>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user