{{ $scr := .Scratch }}
{{/* Request search engines not to index private pages. */}}
{{ if .Params.private }}
{{- end -}}
{{/* Attempt to load superuser (the main site author). */}}
{{ $superuser := index (first 1 (where (where site.Pages "Section" "authors") "Params.superuser" true)) 0 }}
{{ $superuser_name := "" }}
{{ $superuser_username := "" }}
{{ $superuser_role := "" }}
{{ with $superuser }}
{{ $superuser_name = .Title }}
{{ $superuser_username = path.Base .File.Dir }}
{{ $superuser_role = .Params.role }}
{{ end }}
{{/* Set superuser globally for `blox-tailwind/blox-bootstrap` module's `page_author.html`. */}}
{{ $scr.Set "superuser_username" $superuser_username }}
{{ with $superuser_name }}
{{ end }}
{{/* Generate page description. */}}
{{ $desc := "" }}
{{ if .Params.summary }}
{{ $desc = .Params.summary }}
{{ else if .Params.abstract }}
{{ $desc = .Params.abstract }}
{{ else if .IsPage }}
{{ $desc = .Summary }}
{{ else if site.Params.marketing.seo.description }}
{{ $desc = site.Params.marketing.seo.description }}
{{ else }}
{{ $desc = $superuser_role }}
{{ end }}
{{/* Get all URL variations for the page. */}}
{{ range .Translations }}
{{ end }}
{{/* Progressive Web App (PWA) Manifest */}}
{{ with site.Home.OutputFormats.Get "WebAppManifest" }}
{{ end }}
{{/* Progressive Web App (PWA) Icon */}}
{{ $theme_color := ($scr.Get "primary") | default site.Params.appearance.primary_color | default "#fff" }}
{{/* Get page image for social sharing. */}}
{{ $sharing_image := resources.GetMatch (path.Join "media" "sharing.*") }}
{{/* Search for an image "*featured*" in post folder */}}
{{ $featured_image := partial "blox-core/functions/get_featured_image.html" . }}
{{ $avatar_image := (.Resources.ByType "image").GetMatch "avatar*" }}
{{ $has_logo := fileExists "assets/media/logo.png" | or (fileExists "assets/media/logo.svg") }}
{{ $og_image := "" }}
{{ $twitter_card := "summary_large_image" }}
{{ if (and (eq .Kind "term") $avatar_image) }}
{{/* Match image processing in About widget to prevent generating more images than necessary. */}}
{{ $og_image = ($avatar_image.Fill "270x270 Center").Permalink }}
{{ $twitter_card = "summary" }}
{{ else if $featured_image }}
{{ $og_image = $featured_image.Permalink }}
{{ else if $sharing_image }}
{{ $og_image = $sharing_image.Permalink }}
{{ else if $has_logo }}
{{ $og_image = (partial "blox-core/functions/get_logo" (dict "constraint" "fit" "size" 300)).Permalink }}
{{ $twitter_card = "summary" }}
{{ else }}
{{ $og_image = (partial "blox-core/functions/get_icon" 512).Permalink }}
{{ $twitter_card = "summary" }}
{{ end }}
{{ $scr.Set "og_image" $og_image }}{{/* Set `og_image` globally for `rss.xml`. */}}
{{ $title := partial "blox-core/functions/get_page_title" . }}
{{/* Twitter metadata. */}}
{{ with site.Params.marketing.seo.twitter }}
{{ end }}
{{- with $og_image -}}
{{- end -}}
{{/* Open Graph metadata. */}}
{{ $site_type := lower (site.Params.marketing.seo.site_type | default "Person") }}
{{ $og_type := "website" }}
{{ if .IsHome }}
{{ if eq $site_type "person" }}
{{ $og_type = "profile" }}
{{ with $superuser.Params.first_name }}{{end}}
{{ with $superuser.Params.last_name }}{{end}}
{{ else }}
{{ $og_type = "website" }}
{{ end }}
{{ else if .IsPage | and (in (slice "post" "publication" "project" "book") .Type ) }}
{{ $og_type = "article" }}
{{ else }}
{{ $og_type = "website" }}
{{ 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 }}
{{ end }}
{{/* JSONLD page metadata. */}}
{{ partial "jsonld/main" (dict "page" . "summary" $desc) }}