mirror of
https://github.com/jbowdre/runtimeterror.git
synced 2024-11-09 17:42:19 +00:00
add opengraph for share previews
This commit is contained in:
parent
53432fc1a5
commit
eca1287520
2 changed files with 99 additions and 0 deletions
|
@ -6,6 +6,7 @@
|
|||
{{ if .Site.Params.noindex }}<meta name="robots" content="noindex" /> {{ end }}
|
||||
|
||||
{{ partialCached "favicon" . }}
|
||||
{{ partial "opengraph" . }}
|
||||
|
||||
<!-- FontAwesome <https://fontawesome.com/> -->
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.2/css/all.min.css" integrity="sha512-1sCRPdkRXhBV2PBLUdRb4tMg1w2YPf37qatUFeS7zlBy7jJI8Lf4VHwWfZZfpXtYSLy85pkm9GaYVYMfw5BC1A==" crossorigin="anonymous" />
|
||||
|
|
98
layouts/partials/opengraph.html
Normal file
98
layouts/partials/opengraph.html
Normal file
|
@ -0,0 +1,98 @@
|
|||
{{- $summary := truncate 160 .Summary }}
|
||||
{{- $s := .Site.Params }}
|
||||
{{- $p := .Params }}
|
||||
|
||||
{{- $relpath := "" -}}
|
||||
{{- if or $s.usePageBundles $p.usePageBundles }}
|
||||
{{- $relpath = .Page.RelPermalink -}}
|
||||
{{- end }}
|
||||
|
||||
{{ if eq $p.usePageBundles false }}
|
||||
{{- $relpath = "" }}
|
||||
{{ end }}
|
||||
|
||||
{{- with $p.description }}
|
||||
{{- $summary = truncate 160 . }}
|
||||
{{- end }}
|
||||
{{- if .IsHome }}
|
||||
{{- $summary = $s.description }}
|
||||
{{- with $p.description }}
|
||||
{{- $summary = . }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- $site := .Site.Title }}
|
||||
{{- $title := .Title }}
|
||||
{{- $permalink := .Permalink }}
|
||||
{{- $logo := absURL $s.logo }}
|
||||
{{- $author := $s.author }}
|
||||
{{- with $p.author }}
|
||||
{{ $author := . }}
|
||||
{{- end }}
|
||||
{{- $image := absURL $s.fallBackOgImage }}
|
||||
{{- with $p.featureImage }}
|
||||
{{- $fullpath := ( add $relpath . ) -}}
|
||||
{{- $image = absURL $fullpath }}
|
||||
{{- end }}
|
||||
{{- with $p.thumbnail }}
|
||||
{{- $fullpath := ( add $relpath . ) -}}
|
||||
{{- $image = absURL $fullpath }}
|
||||
{{- end }}
|
||||
{{- with $p.shareImage }}
|
||||
{{- $fullpath := ( add $relpath . ) -}}
|
||||
{{- $image = absURL $fullpath }}
|
||||
{{- end }}
|
||||
<meta property="og:locale" content="{{ .Lang }}" />
|
||||
{{- if .IsHome }}
|
||||
<meta property="og:type" content="website">
|
||||
{{- else }}
|
||||
<meta property="og:type" content="article">
|
||||
{{- end }}
|
||||
<meta name="description" content="{{ $summary }}" />
|
||||
<meta property="og:url" content="{{ $permalink }}" />
|
||||
<meta property="og:title" content="{{ $title }}" />
|
||||
<meta property="og:description" content="{{ $summary }}" />
|
||||
<meta property="og:image" content="{{ $image }}" />
|
||||
{{- $keywords := "" }}
|
||||
{{- with $s.keywords }}
|
||||
{{- $keywords = delimit $s.keywords "," }}
|
||||
{{- end }}
|
||||
{{- with $p.keywords }}
|
||||
{{- $keywords = delimit . "," }}
|
||||
{{- end }}
|
||||
{{- with $keywords }}
|
||||
<meta name="keywords" content="{{ $keywords }}" />
|
||||
{{- end }}
|
||||
{{- if eq .Section $s.blogDir -}}
|
||||
{{- $date := ( .Date.Format "2006-02-01") -}}
|
||||
{{- $date := (time .Date) }}
|
||||
{{- $lastMod := (time .Lastmod) }}
|
||||
<script type="application/ld+json">
|
||||
{
|
||||
"@context": "http://schema.org",
|
||||
"@type": "BlogPosting",
|
||||
"mainEntityOfPage":"{{ $permalink }}",
|
||||
"name": "{{ $site }}",
|
||||
"headline": {{ $title }},
|
||||
"description": {{ $summary }},
|
||||
"url": "{{ $permalink }}",
|
||||
"datePublished": {{ $date }},
|
||||
"dateModified": {{ $lastMod }},
|
||||
"author": {
|
||||
"@type": "Person",
|
||||
"name": "{{ $author }}"
|
||||
},
|
||||
"image":{
|
||||
"@type":"ImageObject",
|
||||
"url": "{{ $image }}"
|
||||
},
|
||||
"publisher": {
|
||||
"@type": "Organization",
|
||||
"logo": {
|
||||
"@type":"ImageObject",
|
||||
"url": "{{ $logo }}"
|
||||
},
|
||||
"name": "{{ $site }}"
|
||||
}
|
||||
}
|
||||
</script>
|
||||
{{- end }}
|
Loading…
Reference in a new issue