7
1
mirror of https://gitlab.com/ansol/web-ansol.org.git synced 2024-12-29 07:06:05 +00:00
web-ansol.org/themes/academic/layouts/partials/open_graph.html

51 lines
2.6 KiB
HTML

{{- $scr := .Scratch -}}
{{- $cover_image := (.Resources.ByType "image").GetMatch "*cover*" -}}
{{- $cartaz_image := (.Resources.ByType "image").GetMatch "*cartaz*" -}}
{{- $avatar_image := (.Resources.ByType "image").GetMatch "avatar*" -}}
{{- $has_logo := fileExists "assets/images/logo.png" | or (fileExists "assets/images/logo.svg") -}}
{{- $og_image := "" -}}
{{- $twitter_card := "summary_large_image" -}}
{{- if (and (eq .Kind "taxonomy") $avatar_image) -}}
{{- $og_image = ($avatar_image.Fill "270x270 Center").Permalink -}}
{{- $twitter_card = "summary" -}}
{{- else if $cartaz_image -}}
{{- $og_image = $cartaz_image.Permalink -}}
{{- else if $cover_image -}}
{{- $og_image = $cover_image.Permalink -}}
{{- else if .Params.header.image -}}
{{- $og_image = printf "images/%s" .Params.header.image | absURL -}}
{{- else if site.Params.sharing_image -}}
{{- $og_image = printf "img/%s" site.Params.sharing_image | absURL -}}
{{- else if $has_logo -}}
{{- $og_image = (partial "functions/get_logo" (dict "constraint" "fit" "size" 300)).Permalink -}}
{{- $twitter_card = "summary" -}}
{{- else -}}
{{- $og_image = (partial "functions/get_icon" 512).Permalink -}}
{{- $twitter_card = "summary" -}}
{{- end -}}
{{- $scr.Set "og_image" $og_image -}}
<meta property="twitter:card" content="{{ $twitter_card }}">
{{ with site.Params.twitter -}}
<meta property="twitter:site" content="@{{ . }}">
<meta property="twitter:creator" content="@{{ . }}">
{{ end -}}
<meta property="og:site_name" content="{{ site.Title }}">
<meta property="og:url" content="{{ .Permalink }}">
<meta property="og:title" content="{{ if not .IsHome }}{{ .Title }} | {{ end }}{{ site.Title }}">
<meta property="og:description" content="{{ $scr.Get "desc" }}">
{{ with $og_image -}}
<meta property="og:image" content="{{.}}">
<meta property="twitter:image" content="{{.}}">
{{ end -}}
<meta property="og:locale" content="{{ site.LanguageCode | default "en-us" }}">
{{ if .IsPage }}
{{ if not .PublishDate.IsZero }}
<meta property="article:published_time" content="{{ .PublishDate.Format "2006-01-02T15:04:05-07:00" | safeHTML }}">
{{ else if not .Date.IsZero }}
<meta property="article:published_time" content="{{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML }}">
{{ end }}
{{ if not .Lastmod.IsZero }}<meta property="article:modified_time" content="{{ .Lastmod.Format "2006-01-02T15:04:05-07:00" | safeHTML }}">{{ end }}
{{ else if not .Date.IsZero -}}
<meta property="og:updated_time" content="{{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML }}">
{{ end -}}