From 0ec5a0769f3c2dc851948a1011fa9062ff5c657b Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Thu, 2 Oct 2025 19:08:41 +0200 Subject: feat(backend): customize header image and favicon --- backend/data.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'backend/data.go') diff --git a/backend/data.go b/backend/data.go index 85e8681..8b65531 100644 --- a/backend/data.go +++ b/backend/data.go @@ -4,9 +4,14 @@ import ( "fmt" "html/template" "net/http" + "regexp" "strings" ) +var ( + regexIsHttp = regexp.MustCompile(`^https?://`) +) + type data struct { title string Article bool @@ -16,6 +21,7 @@ type data struct { Description string Name string Links []Link + Logo *Logo } func (d *data) handleGeneric(w http.ResponseWriter, r *http.Request, name string) { @@ -32,6 +38,9 @@ func (d *data) handleGeneric(w http.ResponseWriter, r *http.Request, name string if d.Links == nil { d.Links = cfg.Links } + if d.Logo == nil { + d.Logo = &cfg.Logo + } if d.URL == "" { if !strings.HasPrefix(r.URL.Path, "/") { r.URL.Path = "/" + r.URL.Path @@ -40,9 +49,15 @@ func (d *data) handleGeneric(w http.ResponseWriter, r *http.Request, name string } t, err := template.New("").Funcs(template.FuncMap{ "static": func(path string) string { + if regexIsHttp.MatchString(path) { + return path + } return fmt.Sprintf("/static/%s", path) }, "assets": func(path string) string { + if regexIsHttp.MatchString(path) { + return path + } return fmt.Sprintf("/assets/%s", path) }, }).ParseFS(templates, fmt.Sprintf("templates/%s.html", name), "templates/base.html") -- cgit v1.2.3