fix twitter card images for pngs and absolute urls

This commit is contained in:
Wouter Groeneveld 2021-06-18 16:10:05 +02:00
parent 898a456df5
commit bb29d00d99
1 changed files with 11 additions and 6 deletions

View File

@ -1,11 +1,12 @@
{{ $perm := .Permalink }}
{{ $base := .Site.BaseURL }}
{{ $logo := "img/avatar-icon.png" }}
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="canonical" href="{{ $perm }}">
<link rel="me" title="Mastodon" href="{{ .Site.Author.mastodonlink }}" />
<link rel="me" title="Github" href="{{ .Site.Author.githublink }}" />
<link rel="author" href="{{ .Site.BaseURL }}humans.txt" type="text/plain" />
<link rel="author" href="{{ $base }}humans.txt" type="text/plain" />
<link rel="webmention" href="https://jam.brainbaking.com/webmention" />
<link rel="pingback" href="https://jam.brainbaking.com/pingback" />
@ -57,10 +58,14 @@
</style>
{{ end }}
{{ else }}
{{ $match := findRE `!\[\]\((.+).jpg` .RawContent 1 }}
{{ $match := findRE `!\[(.*)\]\((.+).(jpg|png|gif)` .RawContent 1 }}
{{ range $match }}
{{ $relthumb := replace . "![](" "" }}
{{ $thumb = printf "%s%s" $perm $relthumb }}
{{ $relthumb := replaceRE `!\[(.*)\]\(` "" . }}
{{ if hasPrefix $relthumb "/" }}
{{ $thumb = printf "%s%s" $base $relthumb }}
{{ else }}
{{ $thumb = printf "%s%s" $perm $relthumb }}
{{ end }}
{{ end }}
{{ end }}
<meta name="twitter:image" property="og:image" content="{{ $thumb }}" />
@ -90,7 +95,7 @@
"@type" : "BlogPosting",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": {{ .Site.BaseURL }}
"@id": {{ $base }}
},
"articleSection" : "{{ .Section }}",
"name" : {{ .Title }},
@ -118,7 +123,7 @@
"publisher": {
"@type": "Organization",
"name": "{{ .Site.Title }}",
"url": {{ .Site.BaseURL }},
"url": {{ $base }},
"logo": {
"@type": "ImageObject",
"url": {{ $logo | absURL }},