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
This commit is contained in:
parent
8fc3692e21
commit
51544d5c62
2 changed files with 73 additions and 76 deletions
|
@ -1,8 +1,5 @@
|
||||||
{% if page.author and site.data.authors[page.author] %}
|
{% assign author = page.author | default: page.authors[0] | default: site:author %}
|
||||||
{% assign author = site.data.authors[page.author] %}
|
{% assign author = site.data.authors[author] | default: author %}
|
||||||
{% else %}
|
|
||||||
{% assign author = site.author %}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<div itemscope itemtype="http://schema.org/Person">
|
<div itemscope itemtype="http://schema.org/Person">
|
||||||
|
|
||||||
|
|
|
@ -1,76 +1,77 @@
|
||||||
<!-- begin SEO -->
|
<!-- begin _includes/seo.html -->
|
||||||
{% if site.url %}
|
{%- if site.url -%}
|
||||||
{% assign seo_url = site.url | append: site.baseurl %}
|
{%- assign seo_url = site.url | append: site.baseurl -%}
|
||||||
{% endif %}
|
{%- endif -%}
|
||||||
{% assign seo_url = seo_url | default: site.github.url %}
|
{%- assign seo_url = seo_url | default: site.github.url -%}
|
||||||
|
|
||||||
{% if page.title %}
|
{%- if page.title -%}
|
||||||
{% assign seo_title = page.title | append: " " | append: site.title_separator | append: " " | append: site.title %}
|
{%- assign seo_title = page.title | append: " " | append: site.title_separator | append: " " | append: site.title -%}
|
||||||
{% endif %}
|
{%- endif -%}
|
||||||
|
|
||||||
{% if seo_title %}
|
{%- if seo_title -%}
|
||||||
{% assign seo_title = seo_title | markdownify | strip_html | strip_newlines | escape_once %}
|
{%- assign seo_title = seo_title | markdownify | strip_html | strip_newlines | escape_once -%}
|
||||||
{% endif %}
|
{%- endif -%}
|
||||||
|
|
||||||
{% if site.url %}
|
{%- assign canonical_url = page.url | replace: "index.html", "" | absolute_url %}
|
||||||
{% assign canonical_url = page.url | replace: "index.html", "" | prepend: site.url %}
|
|
||||||
{% 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 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 -%}
|
||||||
|
|
||||||
<title>{{ 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 %}</title>
|
<title>{{ 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 %}</title>
|
||||||
|
|
||||||
{% 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 %}
|
|
||||||
|
|
||||||
<meta name="description" content="{{ seo_description }}">
|
<meta name="description" content="{{ seo_description }}">
|
||||||
|
|
||||||
{% assign seo_author = page.author | default: page.author[0] | default: site.author.name %}
|
{% if author.name %}
|
||||||
{% if seo_author %}
|
<meta name="author" content="{{ author.name | default: 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: "@", "" %}
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<meta name="author" content="{{ seo_author }}">
|
<meta property="og:type" content="{{ og_type }}">
|
||||||
|
|
||||||
<meta property="og:locale" content="{{ site.locale | replace: "-", "_" | default: "en_US" }}">
|
<meta property="og:locale" content="{{ site.locale | replace: "-", "_" | default: "en_US" }}">
|
||||||
<meta property="og:site_name" content="{{ site.title }}">
|
<meta property="og:site_name" content="{{ site.title }}">
|
||||||
<meta property="og:title" content="{{ page.title | default: site.title | markdownify | strip_html | strip_newlines | escape_once }}">
|
<meta property="og:title" content="{{ page.title | default: site.title | markdownify | strip_html | strip_newlines | escape_once }}">
|
||||||
|
<meta property="og:url" content="{{ canonical_url }}">
|
||||||
{% if seo_url %}
|
|
||||||
<link rel="canonical" href="{{ page.url | prepend: seo_url | replace: "/index.html", "/" }}">
|
|
||||||
<meta property="og:url" content="{{ page.url | prepend: seo_url | replace: "/index.html", "/" }}">
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if page.excerpt %}
|
{% if page.excerpt %}
|
||||||
<meta property="og:description" content="{{ seo_description }}">
|
<meta property="og:description" content="{{ seo_description }}">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% assign page_large_image = page.header.og_image | default: page.header.overlay_image | default: page.header.image %}
|
{% if page_large_image %}
|
||||||
{% unless page_large_image contains '://' %}
|
<meta property="og:image" content="{{ page_large_image }}">
|
||||||
{% assign page_large_image = page_large_image | absolute_url %}
|
{% elsif page_teaser_image %}
|
||||||
{% endunless %}
|
<meta property="og:image" content="{{ page_teaser_image }}">
|
||||||
{% assign page_large_image = page_large_image | escape %}
|
{% endif %}
|
||||||
|
|
||||||
{% 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 site.twitter.username %}
|
{% if site.twitter.username %}
|
||||||
<meta name="twitter:site" content="@{{ site.twitter.username | replace: "@", "" }}">
|
<meta name="twitter:site" content="@{{ site.twitter.username | replace: "@", "" }}">
|
||||||
|
@ -88,11 +89,19 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if seo_author_twitter %}
|
{% if author_twitter %}
|
||||||
<meta name="twitter:creator" content="@{{ seo_author_twitter }}">
|
<meta name="twitter:creator" content="@{{ author_twitter }}">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if page.date %}
|
||||||
|
<meta property="article:published_time" content="{{ page.date | date_to_xmlschema }}">
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if og_type == "article" and page.last_modified_at %}
|
||||||
|
<meta property="article:modified_time" content="{{ page.last_modified_at | date_to_xmlschema }}">
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if site.facebook %}
|
{% if site.facebook %}
|
||||||
{% if site.facebook.publisher %}
|
{% if site.facebook.publisher %}
|
||||||
<meta property="article:publisher" content="{{ site.facebook.publisher }}">
|
<meta property="article:publisher" content="{{ site.facebook.publisher }}">
|
||||||
|
@ -103,22 +112,13 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if page_large_image %}
|
<link rel="canonical" href="{{ canonical_url }}">
|
||||||
<meta property="og:image" content="{{ page_large_image }}">
|
|
||||||
{% elsif page_teaser_image %}
|
|
||||||
<meta property="og:image" content="{{ page_teaser_image }}">
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if page.date %}
|
|
||||||
<meta property="og:type" content="article">
|
|
||||||
<meta property="article:published_time" content="{{ page.date | date_to_xmlschema }}">
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if paginator.previous_page %}
|
{% if paginator.previous_page %}
|
||||||
<link rel="prev" href="{{ paginator.previous_page_path | prepend: seo_url }}">
|
<link rel="prev" href="{{ paginator.previous_page_path | absolute_url }}">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if paginator.next_page %}
|
{% if paginator.next_page %}
|
||||||
<link rel="next" href="{{ paginator.next_page_path | prepend: seo_url }}">
|
<link rel="next" href="{{ paginator.next_page_path | absolute_url }}">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if site.og_image %}
|
{% if site.og_image %}
|
||||||
|
@ -159,4 +159,4 @@
|
||||||
{% if site.naver-site-verification %}
|
{% if site.naver-site-verification %}
|
||||||
<meta name="naver-site-verification" content="{{ site.naver-site-verification }}">
|
<meta name="naver-site-verification" content="{{ site.naver-site-verification }}">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<!-- end SEO -->
|
<!-- end _includes/seo.html -->
|
||||||
|
|
Loading…
Reference in a new issue