ensure site.data.authors is in the expected format before resolving author meta

This commit is contained in:
Ben Balter 2017-08-22 11:39:52 -04:00
parent 6ad02a583d
commit f78999819f
No known key found for this signature in database
GPG Key ID: DBB67C246AD356C4
2 changed files with 15 additions and 10 deletions

View File

@ -239,15 +239,20 @@ module Jekyll
end
end
# Given a string representing the current document's author, return
# a normalized hash representing that author. Will try to pull from
# site.authors if present and in the proper format.
def author_hash(author_string)
if site.data["authors"] && site.data["authors"][author_string]
hash = site.data["authors"][author_string]
hash["name"] ||= author_string
hash["twitter"] ||= author_string
hash
else
{ "name" => author_string }
end
site_author_hash(author_string) || { "name" => author_string }
end
def site_author_hash(author_string)
return unless site.data["authors"] && site.data["authors"].is_a?(Hash)
author_hash = site.data["authors"][author_string]
return unless author_hash.is_a?(Hash)
author_hash["name"] ||= author_string
author_hash["twitter"] ||= author_string
author_hash
end
def seo_name

View File

@ -232,11 +232,11 @@ RSpec.describe Jekyll::SeoTag::Drop do
end
context "with site.authors as an array" do
let("data") { ["foo", "bar"] }
let("data") { { "authors" => ["foo", "bar"] } }
let(:page_meta) { {"author" => "foo"} }
it "doesn't error" do
expect(subject.author).to eql("")
expect(subject.author).to eql({"name"=>"foo", "twitter"=>"foo"})
end
end