diff --git a/lib/jekyll-seo-tag/json_ld.rb b/lib/jekyll-seo-tag/json_ld.rb index 4439039..318685f 100644 --- a/lib/jekyll-seo-tag/json_ld.rb +++ b/lib/jekyll-seo-tag/json_ld.rb @@ -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 diff --git a/spec/jekyll_seo_tag/json_ld_spec.rb b/spec/jekyll_seo_tag/json_ld_spec.rb index e920e8f..88b987a 100644 --- a/spec/jekyll_seo_tag/json_ld_spec.rb +++ b/spec/jekyll_seo_tag/json_ld_spec.rb @@ -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