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
Title() string
ImageUrl() string
SetID(id string)
SetPublishedAt(publishedAt *time.Time)
@ -40,6 +41,10 @@ func (e *EntryBase) PublishedAt() *time.Time {
return e.publishedAt
}
func (e *EntryBase) ImageUrl() string {
return ""
}
func (e *EntryBase) SetID(id string) {
e.id = id
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,15 @@
{{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"}}
{{ if not .Entry.PublishedAt }}
@ -16,7 +26,7 @@
<h1 class="p-name">{{.Entry.Title}}</h1>
{{end}}
<small>
<a class="u-url" href="">#</a>
<a class="u-url" href="/posts/{{ .Entry.ID }}/">#</a>
Published:
{{ if .Entry.PublishedAt }}
<time class="dt-published" datetime="{{.Entry.PublishedAt.Format "2006-01-02T15:04:05" }}">

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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