mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-21 10:27:45 +02:00
Merge pull request #578 from hitalos/dev
Support embed icons on bookmarks URLs
This commit is contained in:
commit
1cf4f520f8
@ -3,6 +3,7 @@ package glance
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
@ -115,7 +116,7 @@ func (d *durationField) UnmarshalYAML(node *yaml.Node) error {
|
||||
}
|
||||
|
||||
type customIconField struct {
|
||||
URL string
|
||||
URL template.URL
|
||||
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
|
||||
@ -127,13 +128,13 @@ func newCustomIconField(value string) customIconField {
|
||||
|
||||
prefix, icon, found := strings.Cut(value, ":")
|
||||
if !found {
|
||||
field.URL = value
|
||||
field.URL = template.URL(value)
|
||||
return field
|
||||
}
|
||||
|
||||
switch prefix {
|
||||
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
|
||||
case "di", "sh":
|
||||
// syntax: di:<icon_name>[.svg|.png]
|
||||
@ -152,12 +153,12 @@ func newCustomIconField(value string) customIconField {
|
||||
}
|
||||
|
||||
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 {
|
||||
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:
|
||||
field.URL = value
|
||||
field.URL = template.URL(value)
|
||||
}
|
||||
|
||||
return field
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"html/template"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/text/language"
|
||||
"golang.org/x/text/message"
|
||||
@ -53,6 +54,7 @@ var globalTemplateFunctions = template.FuncMap{
|
||||
|
||||
return template.HTML(value + ` <span class="color-base size-h5">` + label + `</span>`)
|
||||
},
|
||||
"hasPrefix": strings.HasPrefix,
|
||||
}
|
||||
|
||||
func mustParseTemplate(primary string, dependencies ...string) *template.Template {
|
||||
|
Loading…
x
Reference in New Issue
Block a user