98 lines
4.4 KiB
HTML
98 lines
4.4 KiB
HTML
{{- /* 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 -}}{{- if gt (int .) 0 -}}{{- $data = merge $data (dict "foundingDate" (printf "%d" (int .))) -}}{{- end -}}{{- end -}}
|
|
<script type="application/ld+json">{{ $data | jsonify | safeJS }}</script>
|
|
|
|
{{- 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
|
|
-}}
|
|
<script type="application/ld+json">{{ $data | jsonify | safeJS }}</script>
|
|
{{- 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 -}}
|
|
<script type="application/ld+json">{{ $data | jsonify | safeJS }}</script>
|
|
{{- 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 -}}
|
|
<script type="application/ld+json">{{ $data | jsonify | safeJS }}</script>
|
|
{{- 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
|
|
-}}
|
|
<script type="application/ld+json">{{ $data | jsonify | safeJS }}</script>
|
|
{{- end -}}
|
|
{{- end -}}
|