ensure site.data.authors is in the expected format before resolving author meta
This commit is contained in:
parent
6ad02a583d
commit
f78999819f
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue