output image as an imageObject if we have additional image properties

This commit is contained in:
Ben Balter 2017-04-11 16:33:13 -05:00
parent a77929d707
commit bc0f45ae64
No known key found for this signature in database
GPG Key ID: DBB67C246AD356C4
2 changed files with 36 additions and 7 deletions

View File

@ -9,7 +9,7 @@ module Jekyll
:name => "name",
:page_title => "headline",
:json_author => "author",
:image_path => "image",
:json_image => "image",
:date_published => "datePublished",
:date_modified => "dateModified",
:description => "description",
@ -44,8 +44,14 @@ module Jekyll
}
end
def image_path
image["path"] if image
def json_image
return unless image
return image["path"] if image.length == 1
hash = image.dup
hash["url"] = hash.delete("path")
hash["@type"] = "imageObject"
hash
end
def publisher

View File

@ -4,11 +4,12 @@ RSpec.describe Jekyll::SeoTag::JSONLD do
end
let(:author) { "author" }
let(:image) { "image" }
let(:metadata) do
{
"title" => "title",
"author" => author,
"image" => "image",
"image" => image,
"date" => "2017-01-01",
"description" => "description",
"seo" => {
@ -70,9 +71,31 @@ RSpec.describe Jekyll::SeoTag::JSONLD do
end
end
it "returns the image" do
expect(subject).to have_key("image")
expect(subject["image"]).to eql("/image")
context "image" do
context "with image as a string" do
let(:image) { "image" }
it "returns the image as a string" do
expect(subject).to have_key("image")
expect(subject["image"]).to be_a(String)
expect(subject["image"]).to eql("/image")
end
end
context "with image as a hash" do
let(:image) { { "path" => "image", "height" => 5, "width" => 10 } }
it "returns the image as a hash" do
expect(subject).to have_key("image")
expect(subject["image"]).to be_a(Hash)
expect(subject["image"]).to eql({
"@type" => "imageObject",
"url" => "/image",
"height" => 5,
"width" => 10,
})
end
end
end
it "returns the datePublished" do