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/config.go | 10 ++++++++++ backend/data.go | 15 +++++++++++++++ backend/templates/base.html | 3 ++- 3 files changed, 27 insertions(+), 1 deletion(-) (limited to 'backend') diff --git a/backend/config.go b/backend/config.go index 5e6620b..d6eec64 100644 --- a/backend/config.go +++ b/backend/config.go @@ -13,11 +13,17 @@ type Link struct { URL string `toml:"url"` } +type Logo struct { + Header string `toml:"header"` + Favicon string `toml:"favicon"` +} + type Config struct { Domain string `toml:"domain"` Name string `toml:"name"` Description string `toml:"description"` Links []Link `toml:"links"` + Logo Logo `toml:"logo"` } func (c *Config) DefaultValues() { @@ -34,6 +40,10 @@ func (c *Config) DefaultValues() { URL: "/log/", }, } + c.Logo = Logo{ + Header: "logo.jpg", + Favicon: "favicon.jpg", + } } func LoadConfig(path string) (*Config, bool) { 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") diff --git a/backend/templates/base.html b/backend/templates/base.html index ec3f25a..34a7c7f 100644 --- a/backend/templates/base.html +++ b/backend/templates/base.html @@ -5,6 +5,7 @@ {{ .Title }} + @@ -24,7 +25,7 @@
- pfp + Logo -- cgit v1.2.3