From cc2f31d6d5f47472e7162c9aec605587f0abaad8 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Thu, 2 Oct 2025 18:49:06 +0200 Subject: feat(backend): config name and description --- backend/config.go | 6 +++++- backend/data.go | 16 +++++++++++++--- backend/home.go | 10 +--------- backend/templates/base.html | 4 ++-- 4 files changed, 21 insertions(+), 15 deletions(-) (limited to 'backend') diff --git a/backend/config.go b/backend/config.go index 98aeebe..15cc585 100644 --- a/backend/config.go +++ b/backend/config.go @@ -9,11 +9,15 @@ import ( ) type Config struct { - Domain string `toml:"domain"` + Domain string `toml:"domain"` + Name string `toml:"name"` + Description string `toml:"description"` } func (c *Config) DefaultValues() { c.Domain = "example.org" + c.Name = "example" + c.Description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim aeque doleamus animo, cum corpore dolemus, fieri tamen permagna accessio potest, si aliquod aeternum et infinitum impendere malum nobis opinemur. Quod idem licet transferre in voluptatem, ut." } func LoadConfig(path string) (*Config, bool) { diff --git a/backend/data.go b/backend/data.go index 3bc93d1..fd05fa9 100644 --- a/backend/data.go +++ b/backend/data.go @@ -14,15 +14,25 @@ type data struct { URL string Image string Description string + Name string } func (d *data) handleGeneric(w http.ResponseWriter, r *http.Request, name string) { + cfg := r.Context().Value("config").(*Config) if d.Domain == "" { - cfg := r.Context().Value("config").(*Config) d.Domain = cfg.Domain } + if d.Name == "" { + d.Name = cfg.Name + } + if d.Description == "" { + d.Description = cfg.Description + } if d.URL == "" { - d.URL = strings.TrimPrefix(r.URL.Path, "/") + if !strings.HasPrefix(r.URL.Path, "/") { + r.URL.Path = "/" + r.URL.Path + } + d.URL = r.URL.Path } t, err := template.New("").Funcs(template.FuncMap{ "static": func(path string) string { @@ -42,7 +52,7 @@ func (d *data) handleGeneric(w http.ResponseWriter, r *http.Request, name string } func (d *data) Title() string { - title := "anhgelus" + title := d.Name if d.Article { title += " - log entry" } diff --git a/backend/home.go b/backend/home.go index 83e04d9..b70eebf 100644 --- a/backend/home.go +++ b/backend/home.go @@ -8,14 +8,6 @@ import ( func HandleHome(r *chi.Mux) { r.Get("/", func(w http.ResponseWriter, r *http.Request) { - d := &data{ - title: "", - Article: false, - Domain: "anhgelus.world", - URL: "/", - Image: "", - Description: "", - } - d.handleGeneric(w, r, "home") + new(data).handleGeneric(w, r, "home") }) } diff --git a/backend/templates/base.html b/backend/templates/base.html index 922273e..1a7093d 100644 --- a/backend/templates/base.html +++ b/backend/templates/base.html @@ -4,7 +4,7 @@ {{ .Title }} - + @@ -13,7 +13,7 @@ - + -- cgit v1.2.3