aboutsummaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rw-r--r--backend/data.go36
-rw-r--r--backend/home.go15
-rw-r--r--backend/templates/base.html16
3 files changed, 58 insertions, 9 deletions
diff --git a/backend/data.go b/backend/data.go
index adf5db3..e1a8478 100644
--- a/backend/data.go
+++ b/backend/data.go
@@ -1,11 +1,41 @@
package backend
+import (
+ "fmt"
+ "html/template"
+ "net/http"
+)
+
type data struct {
- title string
- Article bool
+ title string
+ Article bool
+ Domain string
+ URL string
+ Image string
+ Description string
+}
+
+func (d *data) handleGeneric(w http.ResponseWriter, name string) {
+ t, err := template.New("").Funcs(template.FuncMap{
+ "static": func(path string) string {
+ return fmt.Sprintf("/static/%s", path)
+ },
+ "assets": func(path string) string {
+ return fmt.Sprintf("/assets/%s", path)
+ },
+ }).ParseFS(templates, fmt.Sprintf("templates/%s.html", name), "templates/base.html")
+ if err != nil {
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
+ err = t.ExecuteTemplate(w, "base.html", d)
+ if err != nil {
+ w.WriteHeader(http.StatusInternalServerError)
+ return
+ }
}
-func (d data) Title() string {
+func (d *data) Title() string {
title := "anhgelus"
if d.Article {
title += " - log entry"
diff --git a/backend/home.go b/backend/home.go
index 8577fec..a7f2ae1 100644
--- a/backend/home.go
+++ b/backend/home.go
@@ -1,18 +1,21 @@
package backend
import (
- "html/template"
"net/http"
"github.com/go-chi/chi/v5"
)
func HandleHome(r *chi.Mux) {
- r.Get("/", func(w http.ResponseWriter, r *http.Request) {
- t := template.Must(template.ParseFS(templates, "templates/home.html", "templates/base.html"))
- err := t.ExecuteTemplate(w, "base.html", &data{})
- if err != nil {
- panic(err)
+ r.Get("/", func(w http.ResponseWriter, _ *http.Request) {
+ d := &data{
+ title: "",
+ Article: false,
+ Domain: "anhgelus.world",
+ URL: "/",
+ Image: "",
+ Description: "",
}
+ d.handleGeneric(w, "home")
})
}
diff --git a/backend/templates/base.html b/backend/templates/base.html
index c994cac..922273e 100644
--- a/backend/templates/base.html
+++ b/backend/templates/base.html
@@ -5,6 +5,22 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{ .Title }}</title>
<link rel="stylesheet" href="/assets/styles.css">
+ <meta property="description" content="{{ .Description }}" />
+ <!-- Open Graph -->
+ <meta property="og:title" content="{{ .Title }}" />
+ <meta property="og:type" content="website" />
+ <meta property="og:url" content="https://{{ .Domain }}{{ .URL }}" />
+ <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" />
+ <!-- Twitter -->
+ <meta name="twitter:card" content="summary_large_image" />
+ <meta property="twitter:domain" content="{{ .Domain }}" />
+ <meta property="twitter:url" content="https://{{ .Domain }}{{ .URL }}/" />
+ <meta name="twitter:title" content="{{ .Title }}" />
+ <meta name="twitter:description" content="{{ .Description }}" />
+ <meta name="twitter:image" content="https://{{ .Domain }}{{ static .Image }}" />
</head>
<body>
<header>