Skip to content

Commit

Permalink
Merge pull request #192 from jekyll/author-by-reference
Browse files Browse the repository at this point in the history
Fix for including name when author is passed by reference
  • Loading branch information
benbalter authored Apr 25, 2017
2 parents 05c8d9f + e0c8173 commit d0b8661
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
1 change: 1 addition & 0 deletions lib/jekyll-seo-tag/drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ def author_string_or_hash
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
Expand Down
30 changes: 19 additions & 11 deletions spec/jekyll_seo_tag/drop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@

context "author" do
let(:data) { {} }
let(:config) { { "author" => "author" } }
let(:config) { { "author" => "site_author" } }
let(:site) do
site = make_site(config)
site.data = data
Expand All @@ -168,7 +168,10 @@
if site_data_type == :with
{
"authors" => {
"author" => { "name" => "Author" },
"author" => { "name" => "data_author", "image" => "author.png" },
"array_author" => { "image" => "author.png" },
"string_author" => { "image" => "author.png" },
"site_author" => { "image" => "author.png" },
},
}
else
Expand All @@ -177,29 +180,34 @@
end

{
:string => { "author" => "author" },
:array => { "authors" => %w(author author2) },
:string => { "author" => "string_author" },
:array => { "authors" => %w(array_author author2) },
:empty_string => { "author" => "" },
:nil => { "author" => nil },
:hash => { "author" => { "name" => "author" } },
:hash => { "author" => { "name" => "hash_author" } },
}.each do |author_type, data|
context "with author as #{author_type}" do
let(:page_meta) { data }
let(:expected_author) do
"#{author_type}_author".sub("nil_", "site_").sub("empty_string_", "site_")
end

it "returns a hash" do
expect(subject.author).to be_a(Hash)
end

it "returns the name" do
if site_data_type == :with && author_type != :hash
expect(subject.author["name"]).to eql("Author")
else
expect(subject.author["name"]).to eql("author")
end
expect(subject.author["name"]).to eql(expected_author)
end

it "returns the twitter handle" do
expect(subject.author["twitter"]).to eql("author")
expect(subject.author["twitter"]).to eql(expected_author)
end

if site_data_type == :with && author_type != :hash
it "returns the image" do
expect(subject.author["image"]).to eql("author.png")
end
end
end
end
Expand Down

0 comments on commit d0b8661

Please sign in to comment.