{{- /* JSON-LD structured data — WebSite on home, BlogPosting on posts */ -}}

{{- if .IsHome -}}
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "WebSite",
  "name": {{ .Site.Title | jsonify }},
  "url": {{ .Site.BaseURL | jsonify }},
  "description": {{ .Site.Params.description | jsonify }},
  "publisher": {
    "@type": "Organization",
    "name": {{ .Site.Title | jsonify }},
    "url": {{ .Site.BaseURL | jsonify }},
    "logo": {
      "@type": "ImageObject",
      "url": {{ "/logo.svg" | absURL | jsonify }}
    }
  }
}
</script>
{{- else if and .IsPage (eq .Section "posts") -}}
{{- $authorPage := "" -}}
{{- with .Params.author -}}
  {{- $authorPage = site.GetPage (printf "authors/%s" .) -}}
{{- end -}}
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "BlogPosting",
  "headline": {{ .Title | jsonify }},
  "description": {{ with .Description }}{{ . | jsonify }}{{ else }}{{ .Site.Params.description | jsonify }}{{ end }},
  "url": {{ .Permalink | jsonify }},
  "datePublished": {{ .Date.Format "2006-01-02T15:04:05Z07:00" | jsonify }},
  "dateModified": {{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" | jsonify }},
  {{- with .Params.banner }}
  "image": {{ .src | absURL | jsonify }},
  {{- else }}
  "image": {{ .Site.Params.ogImage | absURL | jsonify }},
  {{- end }}
  "author": {
    "@type": "Person",
    "name": {{ with $authorPage }}{{ .Params.name | default .Title | jsonify }}{{ else }}{{ .Site.Params.author | jsonify }}{{ end }}{{ with $authorPage }},
    "url": {{ .Permalink | jsonify }}{{ end }}
  },
  "publisher": {
    "@type": "Organization",
    "name": {{ .Site.Title | jsonify }},
    "url": {{ .Site.BaseURL | jsonify }},
    "logo": {
      "@type": "ImageObject",
      "url": {{ "/logo.svg" | absURL | jsonify }}
    }
  },
  "mainEntityOfPage": {
    "@type": "WebPage",
    "@id": {{ .Permalink | jsonify }}
  }{{ with .Params.tags }},
  "keywords": {{ . | jsonify }}{{ end }}
}
</script>
{{- end -}}
