From 1cb467cbac7cebe1c2423c3bbfd9c7e528ce3dbb Mon Sep 17 00:00:00 2001 From: Ilgiz Mustafin Date: Mon, 20 Sep 2021 23:08:49 +0300 Subject: [PATCH] Allow to set author url --- lib/jekyll-seo-tag/json_ld_drop.rb | 7 ++++++- spec/jekyll_seo_tag/json_ld_drop_spec.rb | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/jekyll-seo-tag/json_ld_drop.rb b/lib/jekyll-seo-tag/json_ld_drop.rb index 11d04e3..c892895 100644 --- a/lib/jekyll-seo-tag/json_ld_drop.rb +++ b/lib/jekyll-seo-tag/json_ld_drop.rb @@ -41,10 +41,15 @@ module Jekyll author_type = page_drop.author["type"] return if author_type && !VALID_AUTHOR_TYPES.include?(author_type) - { + hash = { "@type" => author_type || "Person", "name" => page_drop.author["name"], } + + author_url = page_drop.author["url"] + hash["url"] = author_url if author_url + + hash end def image diff --git a/spec/jekyll_seo_tag/json_ld_drop_spec.rb b/spec/jekyll_seo_tag/json_ld_drop_spec.rb index c40f4ed..b9bc627 100644 --- a/spec/jekyll_seo_tag/json_ld_drop_spec.rb +++ b/spec/jekyll_seo_tag/json_ld_drop_spec.rb @@ -95,6 +95,20 @@ RSpec.describe Jekyll::SeoTag::JSONLDDrop do expect(subject["author"]).to be nil end end + + context "when url is present" do + let(:author) { { "name" => "author", "url" => "https://example.com" } } + + it "returns the author with url" do + expect(subject).to have_key("author") + expect(subject["author"]).to be_a(Hash) + expect(subject["author"]).to have_key("url") + expect(subject["author"]["url"]).to eql("https://example.com") + expect(subject["author"]).to have_key("name") + expect(subject["author"]["name"]).to be_a(String) + expect(subject["author"]["name"]).to eql("author") + end + end end context "image" do