{{- /* schema-jsonld.html — emits JSON-LD based on the page's front-matter
schemaType. BreadcrumbList is emitted separately by breadcrumbs.html.
Uses dict + jsonify so all values are safely escaped. */ -}}
{{- $brand := .Site.Data.brand -}}
{{- $type := .Params.schemaType | default "none" -}}
{{- if eq $type "Organization" -}}
{{- $sameAs := slice -}}
{{- range $brand.socialLinks -}}
{{- $sameAs = $sameAs | append .url -}}
{{- end -}}
{{- $data := dict
"@context" "https://schema.org"
"@type" "Organization"
"name" $brand.name
"url" .Site.BaseURL
"logo" ($brand.logoPath | absURL)
"description" $brand.tagline
"sameAs" $sameAs
-}}
{{- with $brand.contactEmail -}}{{- if not (in . ".example") -}}{{- $data = merge $data (dict "email" .) -}}{{- end -}}{{- end -}}
{{- with $brand.foundedYear -}}
{{- $year := printf "%v" . -}}
{{- if gt (len (findRE `^[0-9]{4}$` $year)) 0 -}}
{{- $data = merge $data (dict "foundingDate" $year) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if eq $type "FAQPage" -}}
{{- $faqs := .Params.faqItems | default .Site.Data.faq -}}
{{- $items := slice -}}
{{- range $faqs -}}
{{- $items = $items | append (dict
"@type" "Question"
"name" .question
"acceptedAnswer" (dict "@type" "Answer" "text" .answer)
) -}}
{{- end -}}
{{- if gt (len $items) 0 -}}
{{- $data := dict
"@context" "https://schema.org"
"@type" "FAQPage"
"mainEntity" $items
-}}
{{- end -}}
{{- end -}}
{{- if eq $type "Review" -}}
{{- $authorName := .Params.authorName | default $brand.name -}}
{{- $authorType := cond (isset .Params "authorName") "Person" "Organization" -}}
{{- $data := dict
"@context" "https://schema.org"
"@type" "Review"
"headline" (.Params.h1 | default .Title)
"description" (.Params.description | default .Summary | plainify)
"url" .Permalink
"author" (dict "@type" $authorType "name" $authorName)
"publisher" (dict "@type" "Organization" "name" $brand.name "logo" (dict "@type" "ImageObject" "url" ($brand.logoPath | absURL)))
"itemReviewed" (dict "@type" "Organization" "name" (.Params.reviewedOrganization | default .Title))
"reviewRating" (dict "@type" "Rating" "ratingValue" (.Params.rating | default $brand.ratingValue) "bestRating" 5 "worstRating" 1)
-}}
{{- if not .Date.IsZero -}}{{- $data = merge $data (dict "datePublished" (.Date.Format "2006-01-02")) -}}{{- end -}}
{{- if not .Lastmod.IsZero -}}{{- $data = merge $data (dict "dateModified" (.Lastmod.Format "2006-01-02")) -}}{{- end -}}
{{- else if eq $type "Article" -}}
{{- $authorName := .Params.authorName | default $brand.name -}}
{{- $authorType := cond (isset .Params "authorName") "Person" "Organization" -}}
{{- $data := dict
"@context" "https://schema.org"
"@type" "Article"
"headline" (.Params.h1 | default .Title)
"description" (.Params.description | default .Summary | plainify)
"url" .Permalink
"mainEntityOfPage" (dict "@type" "WebPage" "@id" .Permalink)
"author" (dict "@type" $authorType "name" $authorName)
"publisher" (dict "@type" "Organization" "name" $brand.name "logo" (dict "@type" "ImageObject" "url" ($brand.logoPath | absURL)))
-}}
{{- with (.Params.image | default .Site.Params.ogImage) -}}{{- $data = merge $data (dict "image" (. | absURL)) -}}{{- end -}}
{{- if not .Date.IsZero -}}{{- $data = merge $data (dict "datePublished" (.Date.Format "2006-01-02")) -}}{{- end -}}
{{- if not .Lastmod.IsZero -}}{{- $data = merge $data (dict "dateModified" (.Lastmod.Format "2006-01-02")) -}}{{- end -}}
{{- else if and (eq $type "HowTo") .Params.howToSteps -}}
{{- $steps := slice -}}
{{- range .Params.howToSteps -}}
{{- $steps = $steps | append (dict "@type" "HowToStep" "name" .name "text" .text) -}}
{{- end -}}
{{- if gt (len $steps) 0 -}}
{{- $data := dict
"@context" "https://schema.org"
"@type" "HowTo"
"name" (.Params.h1 | default .Title)
"description" (.Params.description | default .Summary | plainify)
"step" $steps
-}}
{{- end -}}
{{- end -}}