mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-21 18:31:24 +02:00
Change the type of the field
This commit is contained in:
parent
90254b92d2
commit
e11ce5d3d0
@ -3,6 +3,7 @@ package glance
|
|||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -115,7 +116,7 @@ func (d *durationField) UnmarshalYAML(node *yaml.Node) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type customIconField struct {
|
type customIconField struct {
|
||||||
URL string
|
URL template.URL
|
||||||
IsFlatIcon bool
|
IsFlatIcon bool
|
||||||
// TODO: along with whether the icon is flat, we also need to know
|
// 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
|
// whether the icon is black or white by default in order to properly
|
||||||
@ -127,13 +128,13 @@ func newCustomIconField(value string) customIconField {
|
|||||||
|
|
||||||
prefix, icon, found := strings.Cut(value, ":")
|
prefix, icon, found := strings.Cut(value, ":")
|
||||||
if !found {
|
if !found {
|
||||||
field.URL = value
|
field.URL = template.URL(value)
|
||||||
return field
|
return field
|
||||||
}
|
}
|
||||||
|
|
||||||
switch prefix {
|
switch prefix {
|
||||||
case "si":
|
case "si":
|
||||||
field.URL = "https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/" + icon + ".svg"
|
field.URL = template.URL("https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/" + icon + ".svg")
|
||||||
field.IsFlatIcon = true
|
field.IsFlatIcon = true
|
||||||
case "di", "sh":
|
case "di", "sh":
|
||||||
// syntax: di:<icon_name>[.svg|.png]
|
// syntax: di:<icon_name>[.svg|.png]
|
||||||
@ -152,12 +153,12 @@ func newCustomIconField(value string) customIconField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if prefix == "di" {
|
if prefix == "di" {
|
||||||
field.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)
|
||||||
} else {
|
} else {
|
||||||
field.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)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
field.URL = value
|
field.URL = template.URL(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
return field
|
return field
|
||||||
|
@ -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="{{ if hasPrefix .Icon.URL "data:image/" }}{{ .Icon.URL | safeURL }}{{ else }}{{ .Icon.URL }}{{ end }}" 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 | 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>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user