From 9708dc5911f3499a0aa1ee2e5b75255dbdc2b0b7 Mon Sep 17 00:00:00 2001 From: Michael Rose Date: Tue, 9 Jan 2018 13:58:35 -0500 Subject: [PATCH] SEO and author fixes (#1456) * Fix canonical URL * Fix next/previous page paths * Group meta types together * Fix twitter:creator conditional * Allow `author` to accept an object or string * Reduce white-space * Add "website" as default `og:type` * Add `article:modified_time` * Show `article:modified_time` on `article` only Fixes #289 --- _includes/author-profile.html | 7 +- _includes/seo.html | 148 +++++++++++++++++----------------- 2 files changed, 76 insertions(+), 79 deletions(-) diff --git a/_includes/author-profile.html b/_includes/author-profile.html index 8c53519..4d1de88 100644 --- a/_includes/author-profile.html +++ b/_includes/author-profile.html @@ -1,8 +1,5 @@ -{% if page.author and site.data.authors[page.author] %} - {% assign author = site.data.authors[page.author] %} -{% else %} - {% assign author = site.author %} -{% endif %} +{% assign author = page.author | default: page.authors[0] | default: site:author %} +{% assign author = site.data.authors[author] | default: author %}
diff --git a/_includes/seo.html b/_includes/seo.html index 87da33f..1df9394 100644 --- a/_includes/seo.html +++ b/_includes/seo.html @@ -1,76 +1,77 @@ - -{% if site.url %} - {% assign seo_url = site.url | append: site.baseurl %} -{% endif %} -{% assign seo_url = seo_url | default: site.github.url %} - -{% if page.title %} - {% assign seo_title = page.title | append: " " | append: site.title_separator | append: " " | append: site.title %} -{% endif %} - -{% if seo_title %} - {% assign seo_title = seo_title | markdownify | strip_html | strip_newlines | escape_once %} -{% endif %} - -{% if site.url %} - {% assign canonical_url = page.url | replace: "index.html", "" | prepend: site.url %} -{% endif %} + +{%- if site.url -%} + {%- assign seo_url = site.url | append: site.baseurl -%} +{%- endif -%} +{%- assign seo_url = seo_url | default: site.github.url -%} + +{%- if page.title -%} + {%- assign seo_title = page.title | append: " " | append: site.title_separator | append: " " | append: site.title -%} +{%- endif -%} + +{%- if seo_title -%} + {%- assign seo_title = seo_title | markdownify | strip_html | strip_newlines | escape_once -%} +{%- endif -%} + +{%- assign canonical_url = page.url | replace: "index.html", "" | absolute_url %} + +{%- assign seo_description = page.description | default: page.excerpt | default: site.description -%} +{%- if seo_description -%} + {%- assign seo_description = seo_description | markdownify | strip_html | strip_newlines | escape_once -%} +{%- endif -%} + +{%- assign author = page.author | default: page.authors[0] | default: site:author -%} +{%- assign author = site.data.authors[author] | default: author -%} + +{%- if author.twitter -%} + {%- assign author_twitter = author.twitter | replace: "@", "" -%} +{%- endif -%} + +{%- assign page_large_image = page.header.og_image | default: page.header.overlay_image | default: page.header.image -%} +{%- unless page_large_image contains '://' -%} + {%- assign page_large_image = page_large_image | absolute_url -%} +{%- endunless -%} +{%- assign page_large_image = page_large_image | escape -%} + +{%- assign page_teaser_image = page.header.teaser | default: site.og_image -%} +{%- unless page_teaser_image contains '://' -%} + {%- assign page_teaser_image = page_teaser_image | absolute_url -%} +{%- endunless -%} +{%- assign page_teaser_image = page_teaser_image | escape -%} + +{%- assign site_og_image = site.og_image -%} +{%- unless site_og_image contains '://' -%} + {%- assign site_og_image = site_og_image | absolute_url -%} +{%- endunless -%} +{%- assign site_og_image = site_og_image | escape -%} + +{%- if page.date -%} + {%- assign og_type = "article" -%} +{%- else -%} + {%- assign og_type = "website" -%} +{%- endif -%} {{ seo_title | default: site.title }}{% if paginator %}{% unless paginator.page == 1 %} {{ site.title_separator }} {{ site.data.ui-text[site.locale].page | default: "Page" }} {{ paginator.page }}{% endunless %}{% endif %} - -{% assign seo_description = page.description | default: page.excerpt | default: site.description %} -{% if seo_description %} - {% assign seo_description = seo_description | markdownify | strip_html | strip_newlines | escape_once %} -{% endif %} - -{% assign seo_author = page.author | default: page.author[0] | default: site.author.name %} -{% if seo_author %} - {% if seo_author.twitter %} - {% assign seo_author_twitter = seo_author.twitter %} - {% else %} - {% if site.data.authors and site.data.authors[seo_author] %} - {% assign seo_author_twitter = site.data.authors[seo_author].twitter %} - {% else %} - {% assign seo_author_twitter = seo_author %} - {% endif %} - {% endif %} - {% assign seo_author_twitter = seo_author_twitter | replace: "@", "" %} +{% if author.name %} + {% endif %} - - + - -{% if seo_url %} - - -{% endif %} + {% if page.excerpt %} {% endif %} -{% assign page_large_image = page.header.og_image | default: page.header.overlay_image | default: page.header.image %} -{% unless page_large_image contains '://' %} - {% assign page_large_image = page_large_image | absolute_url %} -{% endunless %} -{% assign page_large_image = page_large_image | escape %} - -{% assign page_teaser_image = page.header.teaser | default: site.og_image %} -{% unless page_teaser_image contains '://' %} - {% assign page_teaser_image = page_teaser_image | absolute_url %} -{% endunless %} -{% assign page_teaser_image = page_teaser_image | escape %} - -{% assign site_og_image = site.og_image %} -{% unless site_og_image contains '://' %} - {% assign site_og_image = site_og_image | absolute_url %} -{% endunless %} -{% assign site_og_image = site_og_image | escape %} +{% if page_large_image %} + +{% elsif page_teaser_image %} + +{% endif %} {% if site.twitter.username %} @@ -88,11 +89,19 @@ {% endif %} {% endif %} - {% if seo_author_twitter %} - + {% if author_twitter %} + {% endif %} {% endif %} +{% if page.date %} + +{% endif %} + +{% if og_type == "article" and page.last_modified_at %} + +{% endif %} + {% if site.facebook %} {% if site.facebook.publisher %} @@ -103,22 +112,13 @@ {% endif %} {% endif %} -{% if page_large_image %} - -{% elsif page_teaser_image %} - -{% endif %} - -{% if page.date %} - - -{% endif %} + {% if paginator.previous_page %} - + {% endif %} {% if paginator.next_page %} - + {% endif %} {% if site.og_image %} @@ -159,4 +159,4 @@ {% if site.naver-site-verification %} {% endif %} - + -- 2.43.0