Add favicon
This commit is contained in:
parent
1509789cde
commit
2852be0a87
3 changed files with 30 additions and 1 deletions
23
internal/server/favicon.go
Normal file
23
internal/server/favicon.go
Normal file
|
|
@ -0,0 +1,23 @@
|
||||||
|
package server
|
||||||
|
|
||||||
|
import "net/http"
|
||||||
|
|
||||||
|
const faviconSVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64">
|
||||||
|
<rect width="64" height="64" rx="5" fill="#111111"/>
|
||||||
|
<text x="32" y="35" text-anchor="middle" font-family="ui-monospace, Menlo, Consolas, monospace" font-size="19" font-weight="700" fill="#2ecc71">Rud?</text>
|
||||||
|
<rect x="10" y="40" width="45" height="5" rx="1.5" fill="#2ecc71"/>
|
||||||
|
</svg>`
|
||||||
|
|
||||||
|
func (s *Server) serveFavicon(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.Method != http.MethodGet && r.Method != http.MethodHead {
|
||||||
|
w.Header().Set("Allow", "GET, HEAD")
|
||||||
|
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.Header().Set("Content-Type", "image/svg+xml; charset=utf-8")
|
||||||
|
w.Header().Set("Cache-Control", "public, max-age=86400")
|
||||||
|
if r.Method == http.MethodHead {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, _ = w.Write([]byte(faviconSVG))
|
||||||
|
}
|
||||||
|
|
@ -45,6 +45,10 @@ func (s *Server) SetStats(q StatsQuerier) {
|
||||||
|
|
||||||
// ServeHTTP handles incoming HTTP requests strictly on the configured single endpoint.
|
// ServeHTTP handles incoming HTTP requests strictly on the configured single endpoint.
|
||||||
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if r.URL.Path == "/favicon.svg" {
|
||||||
|
s.serveFavicon(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
if r.URL.Path == "/monitor" || strings.HasPrefix(r.URL.Path, "/monitor/") {
|
if r.URL.Path == "/monitor" || strings.HasPrefix(r.URL.Path, "/monitor/") {
|
||||||
s.serveMonitor(w, r)
|
s.serveMonitor(w, r)
|
||||||
return
|
return
|
||||||
|
|
@ -620,6 +624,7 @@ a:hover { color: var(--accent); }
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
|
||||||
<title>{{.Title}}</title>
|
<title>{{.Title}}</title>
|
||||||
{{template "pagecss" .}}
|
{{template "pagecss" .}}
|
||||||
</head>
|
</head>
|
||||||
|
|
@ -817,6 +822,7 @@ a:hover { color: var(--accent); }
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
|
||||||
<title>{{.Title}}</title>
|
<title>{{.Title}}</title>
|
||||||
{{template "pagecss" .}}
|
{{template "pagecss" .}}
|
||||||
</head>
|
</head>
|
||||||
|
|
|
||||||
2
main.go
2
main.go
|
|
@ -35,7 +35,7 @@ func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *showVersion {
|
if *showVersion {
|
||||||
fmt.Printf("R u ded? (rud) v%s — by tyuXX for GsDistance.org (https://git.gsdistance.org/tyuXX/RUD)\n", Version)
|
fmt.Printf("R u ded? (rud) v%s — by tyuXX (https://git.gsdistance.org/tyuXX/RUD)\n", Version)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue