From 4868d22b1b6342e68f93cd7335859dac2593ed13 Mon Sep 17 00:00:00 2001 From: Kyle Niewiada Date: Tue, 17 Jan 2017 09:39:41 -0500 Subject: [PATCH] Add the rest of the JSON tags to pass blogPosting Errors/Warnings This adds the rest of the JSON fields to pass all errors and blog postings. - Adds page.image.url for the image url. (Will default to image if not present). - Add page.image.height and page.image.width for an image object (Will default back to image url if not present). - Add dateModified (will capture from yaml if present, if not it will use datePublished) - (I feel there should be a manual option for this as I sometimes save parts of my blog that shouldn't update the modified field, but still change the file timestamp). This should create JSON that will pass all warnings/strong recommendations/errors from [Google's Structured Data Testing Tool](https://search.google.com/structured-data/testing-tool). --- lib/template.html | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/lib/template.html b/lib/template.html index 2dea55c..34a972a 100644 --- a/lib/template.html +++ b/lib/template.html @@ -92,7 +92,7 @@ {% endif %} {% if page.image %} - {% assign seo_page_image = page.image.path | default: page.image.facebook | default: page.image %} + {% assign seo_page_image = page.image.path | default: page.image.url | default: page.image.facebook | default: page.image %} {% unless seo_page_image contains "://" %} {% assign seo_page_image = seo_page_image | absolute_url %} {% endunless %} @@ -214,13 +214,28 @@ {% endif %} {% if seo_page_image %} - "image": {{ seo_page_image | jsonify }}, + {% if page.image.height && page.image.width %} + "image": { + "@type": "ImageObject", + "url": {{ seo_page_image | jsonify }}, + "height": {{ page.image.height | jsonify }}, + "width": {{ page.image.width | jsonify }} + }, + {% else %} + "image": {{ seo_page_image | jsonify }}, + {% endif %} {% endif %} {% if page.date %} "datePublished": {{ page.date | date_to_xmlschema | jsonify }}, {% endif %} +{% if page.dateModified %} + "dateModified": {{ page.dateModified | date_to_xmlschema | jsonify }}, +{% elseif page.date %} + "dateModified": {{ page.date | date_to_xmlschema | jsonify }}, +{% endif %} + {% if seo_description %} "description": {{ seo_description | jsonify }}, {% endif %} @@ -238,6 +253,13 @@ }, {% endif %} +{% if seo_type == "BlogPosting" %} + "mainEntityOfPage": { + "@type": "WebPage", + "@id": {{ page.url | replace:'/index.html','/' | absolute_url | jsonify }} + }, +{% endif %} + {% if seo_links %} "sameAs": {{ seo_links | jsonify }}, {% endif %}