diff --git a/layouts/partials/headers.html b/layouts/partials/headers.html index a517e57f9..3555d204d 100644 --- a/layouts/partials/headers.html +++ b/layouts/partials/headers.html @@ -98,3 +98,7 @@ {{ end }} {{ with .Param "twitter_author" }}{{ end }} + + +{{ if and (eq .Section "blog") .IsPage }}{{ partial "json-ld-blog.html" . }}{{ end }} +{{ if .Params.faq }}{{ partial "json-ld-faq.html" . }}{{ end }} diff --git a/layouts/partials/json-ld-blog.html b/layouts/partials/json-ld-blog.html new file mode 100644 index 000000000..0daa9413b --- /dev/null +++ b/layouts/partials/json-ld-blog.html @@ -0,0 +1,30 @@ +{{- $description := default .Site.Params.defaultDescription .Description | markdownify | plainify -}} +{{- $image := .Params.banner | default .Site.Params.default_sharing_image -}} +{{- $baseURL := .Site.BaseURL | strings.TrimRight "/" -}} +{{- $orgName := .Site.Title -}} +{{- with .Site.Params.organization }}{{ $orgName = .name | default $orgName }}{{ end -}} +{{- $logo := .Site.Params.logo | default "" -}} +{{- with .Site.Params.organization }}{{ $logo = .logo | default $logo }}{{ end -}} + +{{- $jsonLd := dict + "@context" "https://schema.org" + "@type" "BlogPosting" + "headline" .Title + "description" $description + "url" .Permalink + "datePublished" (.Date.Format "2006-01-02T15:04:05Z07:00") + "author" (dict "@type" "Organization" "name" $orgName "url" $baseURL) + "publisher" (dict "@type" "Organization" "name" $orgName "logo" (dict "@type" "ImageObject" "url" (printf "%s/%s" $baseURL $logo))) +-}} + +{{- with .Lastmod -}} +{{- $jsonLd = merge $jsonLd (dict "dateModified" (.Format "2006-01-02T15:04:05Z07:00")) -}} +{{- end -}} + +{{- if $image -}} +{{- $jsonLd = merge $jsonLd (dict "image" (printf "%s/%s" $baseURL $image)) -}} +{{- end -}} + + diff --git a/layouts/partials/json-ld-faq.html b/layouts/partials/json-ld-faq.html new file mode 100644 index 000000000..51bcce91e --- /dev/null +++ b/layouts/partials/json-ld-faq.html @@ -0,0 +1,20 @@ +{{- with .Params.faq -}} +{{- $questions := slice -}} +{{- range . -}} +{{- $questions = $questions | append (dict + "@type" "Question" + "name" .question + "acceptedAnswer" (dict "@type" "Answer" "text" .answer) +) -}} +{{- end -}} + +{{- $jsonLd := dict + "@context" "https://schema.org" + "@type" "FAQPage" + "mainEntity" $questions +-}} + + +{{- end -}}