{%- assign site_url = site.url | append: site.baseurl -%} {%- assign canonical_url = page.url | absolute_url -%} {%- assign language = page.lang | default: site.lang | default: "en" -%} {%- assign locale = page.locale | default: site.locale | default: language -%} {%- assign site_name = site.title | strip | jsonify -%} {%- assign site_description = site.description | strip_html | strip_newlines | strip | jsonify -%} {%- assign same_as_links = site.social.links | default: empty -%} {%- assign publisher_logo_path = site.logo | default: site.default_social_image -%} {%- if publisher_logo_path -%} {%- assign publisher_logo = publisher_logo_path | absolute_url -%} {%- endif -%} {%- assign description_source = page.description | default: page.excerpt | default: site.description -%} {%- assign page_description = description_source | strip_html | strip_newlines | strip | jsonify -%} {%- assign page_image_path = page.social_image | default: page.image | default: site.default_social_image | default: site.logo -%} {%- if page_image_path -%} {%- assign page_image = page_image_path | absolute_url -%} {%- endif -%} {%- assign date_published = page.date | date_to_xmlschema -%} {%- assign modified_source = page.last_modified_at | default: page.date -%} {%- assign date_modified = modified_source | date_to_xmlschema -%} {%- capture organization_json -%} { "@context": "https://schema.org", "@type": "Organization", "name": {{ site_name }}, "url": {{ site_url | jsonify }}{%- if publisher_logo -%}, "logo": {{ publisher_logo | jsonify }}{%- endif -%}{%- if same_as_links and same_as_links != empty -%}, "sameAs": {{ same_as_links | jsonify }}{%- endif -%}{%- if site.geo -%}, "location": { "@type": "Place", "name": {{ site.geo.placename | default: site.title | strip | jsonify }}{%- if site.geo.latitude and site.geo.longitude -%}, "geo": { "@type": "GeoCoordinates", "latitude": {{ site.geo.latitude }}, "longitude": {{ site.geo.longitude }} }{%- endif -%}{%- if site.geo.region or site.geo.country -%}, "address": { "@type": "PostalAddress"{%- if site.geo.region -%}, "addressRegion": {{ site.geo.region | jsonify }}{%- endif -%}{%- if site.geo.country -%}, "addressCountry": {{ site.geo.country | jsonify }}{%- endif -%} }{%- endif -%} }{%- endif -%} } {%- endcapture -%} {%- capture website_json -%} { "@context": "https://schema.org", "@type": "WebSite", "name": {{ site_name }}, "url": {{ site_url | jsonify }}, "description": {{ site_description }}, "inLanguage": {{ locale | jsonify }}{%- if same_as_links and same_as_links != empty -%}, "publisher": { "@type": "Organization", "name": {{ site_name }}{%- if publisher_logo -%}, "logo": { "@type": "ImageObject", "url": {{ publisher_logo | jsonify }} }{%- endif -%} }{%- endif -%} } {%- endcapture -%} {%- if page.collection == "posts" or page.layout == "post" -%} {%- capture page_json -%} { "@context": "https://schema.org", "@type": "BlogPosting", "headline": {{ page.title | default: site.title | strip | jsonify }}, "name": {{ page.title | default: site.title | strip | jsonify }}, "description": {{ page_description }}, "inLanguage": {{ language | jsonify }}, "mainEntityOfPage": {{ canonical_url | jsonify }}, "url": {{ canonical_url | jsonify }}, "datePublished": {{ date_published | jsonify }}, "dateModified": {{ date_modified | jsonify }}, "author": { "@type": "Person", "name": {{ page.author | default: site.author.name | default: site.title | strip | jsonify }} }, "publisher": { "@type": "Organization", "name": {{ site_name }}{%- if publisher_logo -%}, "logo": { "@type": "ImageObject", "url": {{ publisher_logo | jsonify }} }{%- endif -%} }{%- if page_image -%}, "image": {{ page_image | jsonify }}{%- endif -%}{%- if page.tags and page.tags != empty -%}, "keywords": {{ page.tags | join: ', ' | jsonify }}{%- endif -%}{%- if page.categories and page.categories != empty -%}, "articleSection": {{ page.categories | first | jsonify }}{%- endif -%} } {%- endcapture -%} {%- if page.collection == "posts" or page.layout == "post" -%} {%- assign primary_category = page.categories | first -%} {%- assign breadcrumb_position = 2 -%} {%- assign home_url = site_url | append: '/' -%} {%- if primary_category -%} {%- assign category_slug = primary_category | slugify -%} {%- assign category_url = site_url | append: '/tags/#' | append: category_slug -%} {%- assign breadcrumb_position = 3 -%} {%- endif -%} {%- capture breadcrumb_items -%} { "@type": "ListItem", "position": 1, "name": "Home", "item": {{ home_url | jsonify }} }{%- if primary_category -%}, { "@type": "ListItem", "position": 2, "name": {{ primary_category | capitalize | jsonify }}, "item": {{ category_url | jsonify }} }{%- endif -%}, { "@type": "ListItem", "position": {{ breadcrumb_position }}, "name": {{ page.title | default: site.title | strip | jsonify }}, "item": {{ canonical_url | jsonify }} } {%- endcapture -%} {%- capture breadcrumbs_json -%} { "@context": "https://schema.org", "@type": "BreadcrumbList", "itemListElement": [ {{ breadcrumb_items | strip }} ] } {%- endcapture -%} {%- endif -%} {%- elsif page.url == '/' or page.layout == 'index' -%} {%- capture page_json -%} { "@context": "https://schema.org", "@type": "Blog", "name": {{ site_name }}, "url": {{ canonical_url | jsonify }}, "description": {{ site_description }}, "inLanguage": {{ language | jsonify }}{%- if publisher_logo -%}, "publisher": { "@type": "Organization", "name": {{ site_name }}, "logo": { "@type": "ImageObject", "url": {{ publisher_logo | jsonify }} } }{%- endif -%} } {%- endcapture -%} {%- else -%} {%- capture page_json -%} { "@context": "https://schema.org", "@type": "WebPage", "name": {{ page.title | default: site.title | strip | jsonify }}, "url": {{ canonical_url | jsonify }}, "description": {{ page_description }}, "inLanguage": {{ language | jsonify }} } {%- endcapture -%} {%- endif -%} {%- capture ld_graph -%} [ {{ organization_json | strip }}, {{ website_json | strip }}{%- if page_json and page_json != '' -%}, {{ page_json | strip }}{%- endif -%}{%- if breadcrumbs_json and breadcrumbs_json != '' -%}, {{ breadcrumbs_json | strip }}{%- endif -%} ] {%- endcapture -%}