diff options
| author | Anhgelus Morhtuuzh <william@herges.fr> | 2025-10-02 19:08:41 +0200 |
|---|---|---|
| committer | Anhgelus Morhtuuzh <william@herges.fr> | 2025-10-02 19:08:41 +0200 |
| commit | 0ec5a0769f3c2dc851948a1011fa9062ff5c657b (patch) | |
| tree | db8cf8a41afd71681275af8bc2a999dafc397930 /backend/data.go | |
| parent | f6c7a85ca04b9285677227d66205856c31a7d364 (diff) | |
feat(backend): customize header image and favicon
Diffstat (limited to 'backend/data.go')
| -rw-r--r-- | backend/data.go | 15 |
1 files changed, 15 insertions, 0 deletions
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") |
