diff --git a/.rubocop.yml b/.rubocop.yml
index 9408010..ee771a6 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -8,3 +8,12 @@ Style/Documentation:
Style/FileName:
Enabled: false
+
+Metrics/AbcSize:
+ Enabled: false
+
+Metrics/CyclomaticComplexity:
+ Enabled: false
+
+Metrics/PerceivedComplexity:
+ Enabled: false
diff --git a/lib/jekyll-seo-tag.rb b/lib/jekyll-seo-tag.rb
index c2e443f..9fed5e4 100644
--- a/lib/jekyll-seo-tag.rb
+++ b/lib/jekyll-seo-tag.rb
@@ -17,12 +17,20 @@ module Jekyll
def payload
{
- 'seo_tag' => { 'version' => VERSION },
- 'page' => context.registers[:page],
- 'site' => context.registers[:site].site_payload['site']
+ 'seo_tag' => { 'version' => VERSION, 'author' => author },
+ 'page' => page,
+ 'site' => site
}
end
+ def page
+ context.registers[:page]
+ end
+
+ def site
+ context.registers[:site].site_payload['site']
+ end
+
def info
{
registers: context.registers,
@@ -45,6 +53,28 @@ 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 1e38b69..23ca2bf 100644
--- a/lib/template.html
+++ b/lib/template.html
@@ -39,38 +39,8 @@
{% assign seo_description = seo_description | markdownify | strip_html | strip_newlines | escape_once %}
{% endif %}
-{% if page.author %}
- {% if site.data.authors[page.author] %}
- {% assign seo_author_name = site.data.authors[page.author].name %}
- {% assign seo_author_twitter = site.data.authors[page.author].twitter | default: seo_author_name %}
- {% elsif page.author.name %}
- {% assign seo_author_name = page.author.name %}
- {% assign seo_author_twitter = page.author.twitter | default: seo_author_name %}
- {% elsif page.author.twitter %}
- {% assign seo_author_twitter = page.author.twitter %}
- {% assign seo_author_twitter = page.author.twitter %}
- {% else %}
- {% assign seo_author_name = page.author %}
- {% assign seo_author_twitter = page.author %}
- {% endif %}
-{% elsif site.author %}
- {% if site.data.authors[site.author] %}
- {% assign seo_author_name = site.data.authors[site.author].name %}
- {% assign seo_author_twitter = site.data.authors[site.author].twitter | default: seo_author_name %}
- {% elsif site.author.name %}
- {% assign seo_author_name = site.author.name %}
- {% assign seo_author_twitter = site.author.twitter | default: seo_author_name %}
- {% else %}
- {% assign seo_author_name = site.author %}
- {% assign seo_author_twitter = site.author %}
- {% endif %}
-{% endif %}
-{% if seo_author_name %}
- {% assign seo_author_name = seo_author_name | strip_html | escape_once %}
-{% endif %}
-
-{% if seo_author_twitter %}
- {% assign seo_author_twitter = seo_author_twitter | replace:"@","" | prepend:"@" | strip_html | escape_once %}
+{% if seo_tag.author %}
+ {% assign seo_author_twitter = seo_tag.author.twitter | replace:"@","" %}
{% endif %}
{% if seo_title %}
@@ -142,7 +112,7 @@
{% endif %}
{% if seo_author_twitter %}
-
+
{% endif %}
{% endif %}