{{- $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 -}}
{{ with site.Params.twitter -}}
{{ end -}}
{{ with $og_image -}}
{{ end -}}
{{ if .IsPage }}
{{ if not .PublishDate.IsZero }}
{{ else if not .Date.IsZero }}
{{ end }}
{{ if not .Lastmod.IsZero }}{{ end }}
{{ else if not .Date.IsZero -}}
{{ end -}}