diff --git a/lib/jekyll-seo-tag.rb b/lib/jekyll-seo-tag.rb index 9fed5e4..c2e443f 100644 --- a/lib/jekyll-seo-tag.rb +++ b/lib/jekyll-seo-tag.rb @@ -17,20 +17,12 @@ module Jekyll def payload { - 'seo_tag' => { 'version' => VERSION, 'author' => author }, - 'page' => page, - 'site' => site + 'seo_tag' => { 'version' => VERSION }, + 'page' => context.registers[:page], + 'site' => context.registers[:site].site_payload['site'] } end - def page - context.registers[:page] - end - - def site - context.registers[:site].site_payload['site'] - end - def info { registers: context.registers, @@ -53,28 +45,6 @@ module Jekyll File.expand_path './template.html', File.dirname(__FILE__) end end - - # Returns a hash representing the post author - # - # Sources, in order: - # - # 1. page.author, if page.author is a hash - # 2. site.author, if site.author is a hash - # 3. site.data.authors[page.author] if page.author is a string - # 4. page.author if page.author is a string - def author - author = page['author'] || site['author'] - return if author.nil? - return author if author.is_a?(Hash) - - if author.is_a?(String) - if site['data']['authors'] && site['data']['authors'][author] - site['data']['authors'][author] - else - { 'twitter' => author } - end - end - end end end diff --git a/lib/template.html b/lib/template.html index 23ca2bf..62ab874 100644 --- a/lib/template.html +++ b/lib/template.html @@ -39,8 +39,18 @@ {% assign seo_description = seo_description | markdownify | strip_html | strip_newlines | escape_once %} {% endif %} -{% if seo_tag.author %} - {% assign seo_author_twitter = seo_tag.author.twitter | replace:"@","" %} +{% assign seo_author = page.author | default: site.author %} +{% 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:"@","" %} {% endif %} {% if seo_title %}