aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2025-10-02 18:49:06 +0200
committerAnhgelus Morhtuuzh <william@herges.fr>2025-10-02 18:49:06 +0200
commitcc2f31d6d5f47472e7162c9aec605587f0abaad8 (patch)
tree76c6bdfc23a973c3244adc856ae78f6b33a61f56
parent49766901293631aeabfc96e8d80aba305f420630 (diff)
feat(backend): config name and description
-rw-r--r--backend/config.go6
-rw-r--r--backend/data.go16
-rw-r--r--backend/home.go10
-rw-r--r--backend/templates/base.html4
4 files changed, 21 insertions, 15 deletions
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 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ .Title }}</title>
- <link rel="stylesheet" href="/assets/styles.css">
+ <link rel="stylesheet" href="{{ assets "styles.css" }}">
<meta property="description" content="{{ .Description }}" />
<!-- Open Graph -->
<meta property="og:title" content="{{ .Title }}" />
@@ -13,7 +13,7 @@
<meta property="og:image" content="https://{{ .Domain }}{{ static .Image }}" />
<meta property="og:description" content="{{ .Description }}" />
<meta property="og:local" content="fr_FR" />
- <meta property="og:site_name" content="{{ .Title }}'s Now page" />
+ <meta property="og:site_name" content="{{ .Name }}" />
<!-- Twitter -->
<meta name="twitter:card" content="summary_large_image" />
<meta property="twitter:domain" content="{{ .Domain }}" />