aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2025-10-02 19:08:41 +0200
committerAnhgelus Morhtuuzh <william@herges.fr>2025-10-02 19:08:41 +0200
commit0ec5a0769f3c2dc851948a1011fa9062ff5c657b (patch)
treedb8cf8a41afd71681275af8bc2a999dafc397930
parentf6c7a85ca04b9285677227d66205856c31a7d364 (diff)
feat(backend): customize header image and favicon
-rw-r--r--backend/config.go10
-rw-r--r--backend/data.go15
-rw-r--r--backend/templates/base.html3
3 files changed, 27 insertions, 1 deletions
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 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ .Title }}</title>
<link rel="stylesheet" href="{{ assets "styles.css" }}">
+ <link rel="shortcut icon" href="{{ static .Logo.Favicon }}">
<meta property="description" content="{{ .Description }}" />
<!-- Open Graph -->
<meta property="og:title" content="{{ .Title }}" />
@@ -24,7 +25,7 @@
</head>
<body>
<header>
- <img src="https://cdn.anhgelus.world/pfp.jpg" alt="pfp">
+ <img src="{{ static .Logo.Header }}" alt="Logo">
<nav>
{{ range .Links }}<a href="{{ .URL }}">{{ .Name }}</a>{{end}}
</nav>