Add OpenGraph image and headers

This commit is contained in:
nemunaire 2025-10-25 02:48:53 +07:00
commit 3c5bd5cbbd
3 changed files with 28 additions and 5 deletions

View file

@ -24,6 +24,7 @@ package web
import ( import (
"encoding/json" "encoding/json"
"flag" "flag"
"fmt"
"io" "io"
"io/fs" "io/fs"
"io/ioutil" "io/ioutil"
@ -131,13 +132,14 @@ func serveOrReverse(forced_url string, cfg *config.Config) gin.HandlerFunc {
v, _ := ioutil.ReadAll(resp.Body) v, _ := ioutil.ReadAll(resp.Body)
v2 := strings.Replace(strings.Replace(string(v), "</head>", "{{ .Head }}</head>", 1), "</body>", "{{ .Body }}</body>", 1) v2 := strings.Replace(strings.Replace(string(v), "</head>", `{{ .Head }}<meta property="og:url" content="{{ .RootURL }}"></head>`, 1), "</body>", "{{ .Body }}</body>", 1)
indexTpl = template.Must(template.New("index.html").Parse(v2)) indexTpl = template.Must(template.New("index.html").Parse(v2))
if err := indexTpl.ExecuteTemplate(c.Writer, "index.html", map[string]string{ if err := indexTpl.ExecuteTemplate(c.Writer, "index.html", map[string]string{
"Body": CustomBodyHTML, "Body": CustomBodyHTML,
"Head": CustomHeadHTML, "Head": CustomHeadHTML,
"RootURL": fmt.Sprintf("https://%s/", c.Request.Host),
}); err != nil { }); err != nil {
log.Println("Unable to return index.html:", err.Error()) log.Println("Unable to return index.html:", err.Error())
} }
@ -157,14 +159,16 @@ func serveOrReverse(forced_url string, cfg *config.Config) gin.HandlerFunc {
f, _ := Assets.Open("index.html") f, _ := Assets.Open("index.html")
v, _ := ioutil.ReadAll(f) v, _ := ioutil.ReadAll(f)
v2 := strings.Replace(string(v), "</head>", "{{ .Head }}</head>", 1) v2 := strings.Replace(strings.Replace(string(v), "</head>", `{{ .Head }}<meta property="og:url" content="{{ .RootURL }}"></head>`, 1), "</body>", "{{ .Body }}</body>", 1)
indexTpl = template.Must(template.New("index.html").Parse(v2)) indexTpl = template.Must(template.New("index.html").Parse(v2))
} }
// Serve template // Serve template
if err := indexTpl.ExecuteTemplate(c.Writer, "index.html", map[string]string{ if err := indexTpl.ExecuteTemplate(c.Writer, "index.html", map[string]string{
"Head": CustomHeadHTML, "Body": CustomBodyHTML,
"Head": CustomHeadHTML,
"RootURL": fmt.Sprintf("https://%s/", c.Request.Host),
}); err != nil { }); err != nil {
log.Println("Unable to return index.html:", err.Error()) log.Println("Unable to return index.html:", err.Error())
} }

View file

@ -3,6 +3,25 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- Open Graph -->
<meta property="og:type" content="website" />
<meta property="og:title" content="happyDeliver - Test Your Email Deliverability" />
<meta
property="og:description"
content="Get detailed insights into your email configuration, authentication, spam score, and more. Open-source, self-hosted, and privacy-focused."
/>
<meta property="og:image" content="/img/og.webp" />
<!-- Twitter -->
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="happyDeliver - Test Your Email Deliverability" />
<meta
name="twitter:description"
content="Get detailed insights into your email configuration, authentication, spam score, and more. Open-source, self-hosted, and privacy-focused."
/>
<meta name="twitter:image" content="/img/og.webp" />
%sveltekit.head% %sveltekit.head%
</head> </head>
<body data-sveltekit-preload-data="hover"> <body data-sveltekit-preload-data="hover">

BIN
web/static/img/og.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB