From 2e01db268dd5909fd36c9de4c395eb99d7fd6ba6 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Thu, 5 Sep 2019 16:34:04 +0100 Subject: [PATCH] feat: add JSON-LD structured data for website, posts, and pubs Forms part of the transition from Microdata to JSON-LD. See #413 --- layouts/partials/jsonld/article.html | 49 ++++++++++++++++++++++++++++ layouts/partials/jsonld/main.html | 14 ++++++++ layouts/partials/jsonld/website.html | 14 ++++++++ layouts/partials/site_head.html | 2 ++ 4 files changed, 79 insertions(+) create mode 100644 layouts/partials/jsonld/article.html create mode 100644 layouts/partials/jsonld/main.html create mode 100644 layouts/partials/jsonld/website.html diff --git a/layouts/partials/jsonld/article.html b/layouts/partials/jsonld/article.html new file mode 100644 index 00000000..1c3b148e --- /dev/null +++ b/layouts/partials/jsonld/article.html @@ -0,0 +1,49 @@ +{{ $page := .page }} +{{ $summary := .summary }} +{{ $featured_image := ($page.Resources.ByType "image").GetMatch "*featured*" }} + +{{/* Get microdata type. */}} +{{ $microdata_type := "Article" }} +{{ if eq $page.Type "post" }} + {{ $microdata_type = "BlogPosting" }} +{{ end }} + +{{/* Get author name. */}} +{{ $author_username := "" }} +{{ if and (not $page.Params.authors) ($page.Scratch.Get "superuser_username") }} + {{ $author_username = $page.Scratch.Get "superuser_username" }} +{{ else if $page.Params.authors }} + {{ $author_username = index $page.Params.authors 0 }} +{{ end }} +{{ $author := "" }} +{{ $taxonomy := "authors" }} +{{ $profile_page := site.GetPage (printf "/%s/%s" $taxonomy $author_username) }} +{{ with $profile_page }} + {{ $author = .Params.name | default .Title }} +{{ end }} + + diff --git a/layouts/partials/jsonld/main.html b/layouts/partials/jsonld/main.html new file mode 100644 index 00000000..0d8f0d36 --- /dev/null +++ b/layouts/partials/jsonld/main.html @@ -0,0 +1,14 @@ +{{ $page := .page }} +{{ $summary := .summary }} + +{{- if $page.IsHome -}} + + {{ partial "jsonld/website.html" $page }} + +{{- else if $page.IsPage -}} + + {{ if or (eq $page.Type "post") (eq $page.Type "publication") }} + {{ partial "jsonld/article.html" (dict "page" $page "summary" $summary) }} + {{ end }} + +{{- end }} diff --git a/layouts/partials/jsonld/website.html b/layouts/partials/jsonld/website.html new file mode 100644 index 00000000..61c7a2bc --- /dev/null +++ b/layouts/partials/jsonld/website.html @@ -0,0 +1,14 @@ + diff --git a/layouts/partials/site_head.html b/layouts/partials/site_head.html index 30ffa17e..3af5023c 100644 --- a/layouts/partials/site_head.html +++ b/layouts/partials/site_head.html @@ -189,6 +189,8 @@ {{ if not .Date.IsZero }}{{ end }} {{ end }} + {{ partial "jsonld/main" (dict "page" . "summary" $desc) }} + {{ partial "cookie_consent" . }} {{ partial "custom_head" . }}