DRY up JSON-LD

This commit is contained in:
Pat Hawks 2016-02-22 18:31:59 -08:00
parent f3e0e78993
commit 11dea25ac8
No known key found for this signature in database
GPG Key ID: F1746FF5F18B3D1B
1 changed files with 37 additions and 18 deletions

View File

@ -1,5 +1,9 @@
<!-- Begin Jekyll SEO tag v{{ seo_tag.version }} -->
{% 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 %}
<title>{{ seo_title }}</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','/' }}"