{{- $author := partial "function/get-author-map.html" .Params.author -}}

<meta name="author" content="{{ $author.name }}">
<meta name="description" content="{{ with .Description }}{{ . }}{{ else }}{{ if .IsPage | and .Summary }}{{ .Summary | plainify }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}">

{{- $keywords := .Keywords -}}
{{- if not $keywords -}}
  {{- if .IsPage | and .Params.tags -}}
    {{- $keywords = .Params.tags -}}
  {{- else -}}
    {{- $keywords = .Site.Params.keywords -}}
  {{- end -}}
{{- end -}}
{{- with $keywords -}}
  <meta name="keywords" content='{{ delimit . ", " }}'>
{{- end -}}

{{- template "_internal/schema.html" . -}}
{{- template "_internal/opengraph.html" . -}}
{{- template "_internal/twitter_cards.html" . -}}
{{- with .Site.Params.social.Twitter -}}
  <meta name="twitter:creator" content="@{{ . }}" />
{{- end -}}

<meta name="application-name" content="{{ .Site.Params.app.title | default .Site.Title }}">
<meta name="apple-mobile-web-app-title" content="{{ .Site.Params.app.title | default .Site.Title }}">

{{- with .Site.Params.app.themeColor -}}
  {{- $color := . -}}
  {{- if ne (len $color) 2 -}}
    {{- $color = dict "light" . "dark" . -}}
  {{- end -}}
  <meta name="theme-color" data-light="{{ $color.light }}" data-dark="{{ $color.dark }}" content="{{ $color.light }}">
{{- end -}}

{{- with .Site.Params.app.tileColor -}}
  <meta name="msapplication-TileColor" content="{{ . }}">
{{- end -}}

{{- /* Mastodon Validation for the site */ -}}
{{- with .Site.Params.social.Mastodon -}}
  {{- $id := "" -}}
  {{- $prefix := "https://mastodon.social/" -}}
  {{- if reflect.IsMap . -}}
    {{- $id = .Id | default .id -}}
    {{- $prefix = .Prefix | default .prefix | default $prefix -}}
  {{- end -}}
  {{- if $id | and $prefix -}}
    {{- $link := printf "%s/%s" $prefix $id -}}
    {{- $email := printf "%s@%s" (strings.TrimPrefix "@" $id) (urls.Parse $prefix).Host -}}
    <link rel="me" href="{{ $link }}" />
    <meta name="fediverse:creator" content="{{ $email }}" />
  {{- end -}}
{{- end -}}
