From 11dea25ac8ff961118e2f2f350e71d6add6297ff Mon Sep 17 00:00:00 2001 From: Pat Hawks Date: Mon, 22 Feb 2016 18:31:59 -0800 Subject: [PATCH] DRY up JSON-LD --- lib/template.html | 55 +++++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/lib/template.html b/lib/template.html index fb14581..cc50943 100644 --- a/lib/template.html +++ b/lib/template.html @@ -1,5 +1,9 @@ +{% if page.url == "/" or page.url == "/about/" %} + {% assign seo_homepage_or_about = true %} +{% endif %} + {% if site.url %} {% assign seo_url = site.url | append: site.baseurl %} {% endif %} @@ -22,6 +26,17 @@ {% endif %} {% endif %} +{% if page.seo and page.seo.name %} + {% assign seo_name = page.seo.name %} +{% elsif seo_homepage_or_about and site.social and site.social.name %} + {% assign seo_name = site.social.name %} +{% elsif seo_homepage_or_about and seo_site_title %} + {% assign seo_name = seo_site_title %} +{% endif %} +{% if seo_name %} + {% assign seo_name = seo_name | markdownify | strip_html | strip_newlines | escape_once %} +{% endif %} + {% if seo_title %} {% assign seo_title = seo_title | markdownify | strip_html | strip_newlines | escape_once %} {% endif %} @@ -53,6 +68,22 @@ {% assign seo_author_twitter = seo_author_twitter | replace:"@","" %} {% endif %} +{% if page.seo and page.seo.type %} + {% assign seo_type = page.seo.type %} +{% elsif seo_homepage_or_about %} + {% assign seo_type = "WebSite" %} +{% elsif page.date %} + {% assign seo_type = "BlogPosting" %} +{% else %} + {% assign seo_type = "WebPage" %} +{% endif %} + +{% if page.seo and page.seo.links %} + {% assign seo_links = page.seo.links %} +{% elsif seo_homepage_or_about and site.social and site.social.links %} + {% assign seo_links = site.social.links %} +{% endif %} + {% if seo_tag.title and seo_title %} {{ seo_title }} {% endif %} @@ -125,22 +156,12 @@ { "@context" : "http://schema.org", -{% if page.seo and page.seo.type %} - "@type" : {{ page.seo.type | jsonify }}, -{% elsif page.url == "/" %} - "@type" : "WebSite", -{% elsif page.date %} - "@type" : "BlogPosting", -{% else %} - "@type" : "WebPage", +{% if seo_type %} + "@type" : {{ seo_type | jsonify }}, {% endif %} -{% if page.seo and page.seo.name %} - "name" : {{ page.seo.name | jsonify }}, -{% elsif page.url == "/" and site.social and site.social.name %} - "name" : {{ site.social.name | jsonify }}, -{% elsif page.url == "/" and seo_site_title %} - "name" : {{ seo_site_title | jsonify }}, +{% if seo_name %} + "name" : {{ seo_name | jsonify }}, {% endif %} {% if seo_page_title %} @@ -163,10 +184,8 @@ "logo": {{ site.logo | prepend: "/" | prepend: seo_url | jsonify }}, {% endif %} -{% if page.seo and page.seo.links %} - "sameAs" : {{ page.seo.links | jsonify }}, -{% elsif (page.url == "/" or page.url == "/about/") and site.social and site.social.links %} - "sameAs" : {{ site.social.links | jsonify }}, +{% if seo_links %} + "sameAs" : {{ seo_links | jsonify }}, {% endif %} "url" : "{{ page.url | prepend: seo_url | replace:'/index.html','/' }}"