Open Graph Meta data

This commit is contained in:
Niko Abeler 2024-02-24 21:21:48 +01:00
parent 8200e3384c
commit f5946ea823
18 changed files with 44 additions and 4 deletions

View File

@ -15,6 +15,7 @@ type Entry interface {
// Optional: can return empty string // Optional: can return empty string
Title() string Title() string
ImageUrl() string
SetID(id string) SetID(id string)
SetPublishedAt(publishedAt *time.Time) SetPublishedAt(publishedAt *time.Time)
@ -40,6 +41,10 @@ func (e *EntryBase) PublishedAt() *time.Time {
return e.publishedAt return e.publishedAt
} }
func (e *EntryBase) ImageUrl() string {
return ""
}
func (e *EntryBase) SetID(id string) { func (e *EntryBase) SetID(id string) {
e.id = id e.id = id
} }

View File

@ -58,6 +58,10 @@ func (e *Image) Title() string {
return e.meta.Title return e.meta.Title
} }
func (e *Image) ImageUrl() string {
return "/media/" + e.meta.ImageId
}
func (e *Image) Content() model.EntryContent { func (e *Image) Content() model.EntryContent {
str, err := render.RenderTemplateToString("entry/Image", e) str, err := render.RenderTemplateToString("entry/Image", e)
if err != nil { if err != nil {

View File

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"embed" "embed"
"io" "io"
"net/url"
"owl-blogs/domain/model" "owl-blogs/domain/model"
"text/template" "text/template"
@ -29,6 +30,10 @@ var funcMap = template.FuncMap{
} }
return html return html
}, },
"urljoin": func(elems ...string) string {
r, _ := url.JoinPath(elems[0], elems[1:]...)
return r
},
} }
func CreateTemplateWithBase(templateName string) (*template.Template, error) { func CreateTemplateWithBase(templateName string) (*template.Template, error) {

View File

@ -6,6 +6,8 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>{{template "title" .Data}} - {{ .SiteConfig.Title }}</title> <title>{{template "title" .Data}} - {{ .SiteConfig.Title }}</title>
<meta property="og:title" content="{{template "title" .Data}}" /> <meta property="og:title" content="{{template "title" .Data}}" />
{{ template "head" .}}
<link rel="webmention" href="/webmention/" /> <link rel="webmention" href="/webmention/" />
<link rel="alternate" type="application/rss+xml" title="RSS" href="/index.xml"> <link rel="alternate" type="application/rss+xml" title="RSS" href="/index.xml">

View File

@ -1,4 +1,5 @@
{{define "title"}}Admin{{end}} {{define "title"}}Admin{{end}}
{{define "head"}}{{end}}
{{define "main"}} {{define "main"}}
<h2 style="margin-bottom: 1rem;">Write</h2> <h2 style="margin-bottom: 1rem;">Write</h2>

View File

@ -1,5 +1,7 @@
{{define "title"}}Configuration{{end}} {{define "title"}}Configuration{{end}}
{{define "head"}}{{end}}
{{define "main"}} {{define "main"}}
<a href="/admin">&larr; Back</a> <a href="/admin">&larr; Back</a>

View File

@ -1,4 +1,5 @@
{{define "title"}}Files{{end}} {{define "title"}}Files{{end}}
{{define "head"}}{{end}}
{{define "main"}} {{define "main"}}

View File

@ -1,4 +1,5 @@
{{define "title"}}Index{{end}} {{define "title"}}Index{{end}}
{{define "head"}}{{end}}
{{define "main"}} {{define "main"}}

View File

@ -1,4 +1,5 @@
{{define "title"}}Editor{{end}} {{define "title"}}Editor{{end}}
{{define "head"}}{{end}}
{{define "main"}} {{define "main"}}

View File

@ -1,5 +1,15 @@
{{define "title"}}{{.Entry.Title}}{{end}} {{define "title"}}{{.Entry.Title}}{{end}}
{{define "head"}}
<meta property="og:url" content="{{ urljoin .SiteConfig.FullUrl "/posts/" .Data.Entry.ID }}/" />
<meta property="og:type" content="article" />
{{ if .Data.Entry.ImageUrl}}
<meta property="og:image" content="{{ urljoin .SiteConfig.FullUrl .Data.Entry.ImageUrl}}" />
{{ end }}
<meta property="og:article:published_time" content="{{.Data.Entry.PublishedAt.Format "2006-01-02T15:04:05" }}" />
<meta property="og:article:section" content="" />
{{end}}
{{define "main"}} {{define "main"}}
{{ if not .Entry.PublishedAt }} {{ if not .Entry.PublishedAt }}
@ -16,7 +26,7 @@
<h1 class="p-name">{{.Entry.Title}}</h1> <h1 class="p-name">{{.Entry.Title}}</h1>
{{end}} {{end}}
<small> <small>
<a class="u-url" href="">#</a> <a class="u-url" href="/posts/{{ .Entry.ID }}/">#</a>
Published: Published:
{{ if .Entry.PublishedAt }} {{ if .Entry.PublishedAt }}
<time class="dt-published" datetime="{{.Entry.PublishedAt.Format "2006-01-02T15:04:05" }}"> <time class="dt-published" datetime="{{.Entry.PublishedAt.Format "2006-01-02T15:04:05" }}">

View File

@ -1,4 +1,5 @@
{{define "title"}}Index{{end}} {{define "title"}}Index{{end}}
{{define "head"}}{{end}}
{{define "main"}} {{define "main"}}
@ -7,7 +8,7 @@
<div class="h-entry"> <div class="h-entry">
<hgroup> <hgroup>
<h3> <h3>
<a class="u-url" href="/posts/{{ .ID }}"> <a class="u-url" href="/posts/{{ .ID }}/">
{{if .Title}} {{if .Title}}
{{ .Title }} {{ .Title }}
{{else}} {{else}}

View File

@ -1,4 +1,5 @@
{{define "title"}}Files{{end}} {{define "title"}}Interactions{{end}}
{{define "head"}}{{end}}
{{define "main"}} {{define "main"}}
@ -21,7 +22,7 @@
<a href="/posts/{{ .EntryID }}">{{ .EntryID }}</a> <a href="/posts/{{ .EntryID }}">{{ .EntryID }}</a>
</td> </td>
<td> <td>
{{ .CreatedAt.Format "2006-01-02 15:04:05" }} {{ .CreatedAt.Format "2006-01-02 15:04" }}
</td> </td>
</tr> </tr>
{{ end }} {{ end }}

View File

@ -1,4 +1,5 @@
{{define "title"}}Index{{end}} {{define "title"}}Index{{end}}
{{define "head"}}{{end}}
{{define "main"}} {{define "main"}}

View File

@ -1,4 +1,5 @@
{{define "title"}}Editor List{{end}} {{define "title"}}Editor List{{end}}
{{define "head"}}{{end}}
{{define "main"}} {{define "main"}}

View File

@ -1,4 +1,5 @@
{{define "title"}}Editor{{end}} {{define "title"}}Editor{{end}}
{{define "head"}}{{end}}
{{define "main"}} {{define "main"}}

View File

@ -1,4 +1,5 @@
{{define "title"}}Editor{{end}} {{define "title"}}Editor{{end}}
{{define "head"}}{{end}}
{{define "main"}} {{define "main"}}

View File

@ -1,4 +1,5 @@
{{define "title"}}Editor{{end}} {{define "title"}}Editor{{end}}
{{define "head"}}{{end}}
{{define "main"}} {{define "main"}}

View File

@ -1,4 +1,5 @@
{{define "title"}}Editor{{end}} {{define "title"}}Editor{{end}}
{{define "head"}}{{end}}
{{define "main"}} {{define "main"}}