Skip to content

Commit f0541ea

Browse files
committed
Refactor icon stuff
1 parent 8f986f1 commit f0541ea

File tree

5 files changed

+8
-11
lines changed

5 files changed

+8
-11
lines changed

docs/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ This assumes that the config you want to print is in your current working direct
188188

189189
## Icons
190190

191-
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:
191+
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:
192192

193193
```yml
194194
icon: si:immich # si for Simple icons https://simpleicons.org/

internal/glance/config-fields.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,15 @@ func (d *durationField) UnmarshalYAML(node *yaml.Node) error {
131131

132132
type customIconField struct {
133133
URL template.URL
134-
IsFlatIcon bool
135-
// TODO: along with whether the icon is flat, we also need to know
136-
// whether the icon is black or white by default in order to properly
137-
// invert the color based on the theme being light or dark
134+
AutoInvert bool
138135
}
139136

140137
func newCustomIconField(value string) customIconField {
141138
const autoInvertPrefix = "auto-invert "
142139
field := customIconField{}
143140

144141
if strings.HasPrefix(value, autoInvertPrefix) {
145-
field.IsFlatIcon = true
142+
field.AutoInvert = true
146143
value = strings.TrimPrefix(value, autoInvertPrefix)
147144
}
148145

@@ -164,12 +161,12 @@ func newCustomIconField(value string) customIconField {
164161

165162
switch prefix {
166163
case "si":
167-
field.IsFlatIcon = true
164+
field.AutoInvert = true
168165
field.URL = template.URL("https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/" + basename + ".svg")
169166
case "di":
170167
field.URL = template.URL("https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/" + ext + "/" + basename + "." + ext)
171168
case "mdi":
172-
field.IsFlatIcon = true
169+
field.AutoInvert = true
173170
field.URL = template.URL("https://cdn.jsdelivr.net/npm/@mdi/svg@latest/svg/" + basename + ".svg")
174171
case "sh":
175172
field.URL = template.URL("https://cdn.jsdelivr.net/gh/selfhst/icons/" + ext + "/" + basename + "." + ext)

internal/glance/templates/bookmarks.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<div class="flex items-center gap-10">
1414
{{- if ne "" .Icon.URL }}
1515
<div class="bookmarks-icon-container">
16-
<img class="bookmarks-icon{{ if .Icon.IsFlatIcon }} flat-icon{{ end }}" src="{{ .Icon.URL }}" alt="" loading="lazy">
16+
<img class="bookmarks-icon{{ if .Icon.AutoInvert }} flat-icon{{ end }}" src="{{ .Icon.URL }}" alt="" loading="lazy">
1717
</div>
1818
{{- end }}
1919
<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>

internal/glance/templates/docker-containers.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{{- range .Containers }}
66
<li class="docker-container flex items-center gap-15">
77
<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">
8-
<img class="docker-container-icon{{ if .Icon.IsFlatIcon }} flat-icon{{ end }}" src="{{ .Icon.URL }}" alt="" loading="lazy">
8+
<img class="docker-container-icon{{ if .Icon.AutoInvert }} flat-icon{{ end }}" src="{{ .Icon.URL }}" alt="" loading="lazy">
99
<div data-popover-html>
1010
<div class="color-highlight text-truncate block">{{ .Image }}</div>
1111
<div>{{ .StateText }}</div>

internal/glance/templates/monitor.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
{{ define "site" }}
2424
{{ if .Icon.URL }}
25-
<img class="monitor-site-icon{{ if .Icon.IsFlatIcon }} flat-icon{{ end }}" src="{{ .Icon.URL }}" alt="" loading="lazy">
25+
<img class="monitor-site-icon{{ if .Icon.AutoInvert }} flat-icon{{ end }}" src="{{ .Icon.URL }}" alt="" loading="lazy">
2626
{{ end }}
2727
<div class="grow min-width-0">
2828
<a class="size-h3 color-highlight text-truncate block" href="{{ .URL | safeURL }}" {{ if not .SameTab }}target="_blank"{{ end }} rel="noreferrer">{{ .Title }}</a>

0 commit comments

Comments
 (0)