runtimeterror/layouts/partials/opengraph.html

61 lines
2.4 KiB
HTML
Raw Permalink Normal View History

2024-02-19 01:50:20 +00:00
{{ $img := resources.Get "og_base.png" }}
{{ $text := "" }}
{{ $font := "" }}
{{ $path := os.Getenv "HUGO_REMOTE_FONT_PATH" }}
{{ with resources.GetRemote $path }}
{{ with .Err }}
{{ errorf "%s" . }}
{{ else }}
{{ $font = . }}
{{ end }}
{{ else }}
{{ errorf "Unable to get resource %q" $path }}
{{ end }}
2024-02-16 22:51:25 +00:00
<meta property="og:title" content="{{ .Title }}" />
<meta property="og:description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}" />
<meta property="og:type" content="{{ if .IsPage }}article{{ else }}website{{ end }}" />
<meta property="og:url" content="{{ .Permalink }}" />
2023-08-21 21:11:42 +00:00
<meta property="og:locale" content="{{ .Lang }}" />
{{- if .IsHome }}
2024-02-19 02:54:57 +00:00
{{ $text = .Site.Params.Description }}
2023-08-21 21:11:42 +00:00
{{- end }}
2024-02-16 22:51:25 +00:00
{{- if .IsPage }}
2024-02-19 02:54:57 +00:00
{{- $iso8601 := "2006-01-02T15:04:05-07:00" -}}
<meta property="article:section" content="{{ .Section }}" />
{{ with .PublishDate }}<meta property="article:published_time" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />{{ end }}
{{ with .Lastmod }}<meta property="article:modified_time" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />{{ end }}
{{ $text = .Page.Title }}
2024-02-19 01:50:20 +00:00
{{ end }}
{{- with .Params.thumbnail }}
2024-02-19 02:54:57 +00:00
{{ $thumbnail := $.Resources.Get . }}
{{ with $thumbnail }}
{{ $img = $img.Filter (images.Overlay (.Process "fit 300x250") 875 38 )}}
{{ end }}
{{ end }}
2024-02-19 01:50:20 +00:00
{{ $img = $img.Filter (images.Text $text (dict
2024-02-16 22:51:25 +00:00
"color" "#d8d8d8"
"size" 64
"linespacing" 2
"x" 40
"y" 300
2024-02-16 22:51:25 +00:00
"font" $font
))}}
{{ $img = resources.Copy (path.Join $.Page.RelPermalink "og.png") $img }}
2024-02-17 04:29:30 +00:00
2024-02-16 22:51:25 +00:00
<meta property="og:image" content="{{$img.Permalink}}">
<meta property="og:image:width" content="{{$img.Width}}" />
<meta property="og:image:height" content="{{$img.Height}}" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="{{ .Title }}" />
<meta name="twitter:description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end -}}"/>
<meta name="twitter:image" content="{{$img.Permalink}}" />
2024-02-17 04:16:30 +00:00
{{- with .Params.audio }}<meta property="og:audio" content="{{ . }}" />{{ end }}
{{- with .Site.Params.title }}<meta property="og:site_name" content="{{ . }}" />{{ end }}
{{- with .Params.videos }}{{- range . }}
<meta property="og:video" content="{{ . | absURL }}" />
{{ end }}{{ end }}