From e884eab01d152472d4675227460831b3f165e493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20Fr=C3=B6hner?= Date: Wed, 6 Jan 2021 11:37:44 +0100 Subject: [PATCH 1/2] Allow to set type for author Referring to https://schema.org/author the values Organization and Person are supported --- lib/jekyll-seo-tag/json_ld_drop.rb | 7 ++++++- spec/jekyll_seo_tag/json_ld_drop_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/jekyll-seo-tag/json_ld_drop.rb b/lib/jekyll-seo-tag/json_ld_drop.rb index 3bd1d46d..66a0efe4 100644 --- a/lib/jekyll-seo-tag/json_ld_drop.rb +++ b/lib/jekyll-seo-tag/json_ld_drop.rb @@ -21,7 +21,9 @@ class JSONLDDrop < Jekyll::Drops::Drop private :logo VALID_ENTITY_TYPES = %w(BlogPosting CreativeWork).freeze + VALID_AUTHOR_TYPES = %w(Organization Person).freeze private_constant :VALID_ENTITY_TYPES + private_constant :VALID_AUTHOR_TYPES # page_drop should be an instance of Jekyll::SeoTag::Drop def initialize(page_drop) @@ -36,10 +38,13 @@ def fallback_data end def author + author_type = page_drop.author["type"] + return unless page_drop.author["name"] + return nil if author_type && !VALID_AUTHOR_TYPES.include?(author_type) { - "@type" => "Person", + "@type" => author_type || "Person", "name" => page_drop.author["name"], } end diff --git a/spec/jekyll_seo_tag/json_ld_drop_spec.rb b/spec/jekyll_seo_tag/json_ld_drop_spec.rb index 68bd2757..c40f4ed0 100644 --- a/spec/jekyll_seo_tag/json_ld_drop_spec.rb +++ b/spec/jekyll_seo_tag/json_ld_drop_spec.rb @@ -72,6 +72,29 @@ end end end + + context "when type Organization" do + let(:author) { { "name" => "organization", "type" => "Organization" } } + + it "returns the author with type" do + expect(subject).to have_key("author") + expect(subject["author"]).to be_a(Hash) + expect(subject["author"]).to have_key("@type") + expect(subject["author"]["@type"]).to eql("Organization") + expect(subject["author"]).to have_key("name") + expect(subject["author"]["name"]).to be_a(String) + expect(subject["author"]["name"]).to eql("organization") + end + end + + context "when invalid type" do + let(:author) { { "name" => "organization", "type" => "Invalid" } } + + it "returns the author with type" do + expect(subject).to have_key("author") + expect(subject["author"]).to be nil + end + end end context "image" do From c0a75f697356bfe5bc97755d18fd30520c0a1494 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20Fr=C3=B6hner?= Date: Mon, 11 Jan 2021 07:28:30 +0100 Subject: [PATCH 2/2] Comments by @ashmaroli implemented --- lib/jekyll-seo-tag/json_ld_drop.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/jekyll-seo-tag/json_ld_drop.rb b/lib/jekyll-seo-tag/json_ld_drop.rb index 66a0efe4..88bb0e0a 100644 --- a/lib/jekyll-seo-tag/json_ld_drop.rb +++ b/lib/jekyll-seo-tag/json_ld_drop.rb @@ -22,8 +22,7 @@ class JSONLDDrop < Jekyll::Drops::Drop VALID_ENTITY_TYPES = %w(BlogPosting CreativeWork).freeze VALID_AUTHOR_TYPES = %w(Organization Person).freeze - private_constant :VALID_ENTITY_TYPES - private_constant :VALID_AUTHOR_TYPES + private_constant :VALID_ENTITY_TYPES, :VALID_AUTHOR_TYPES # page_drop should be an instance of Jekyll::SeoTag::Drop def initialize(page_drop) @@ -38,10 +37,10 @@ def fallback_data end def author - author_type = page_drop.author["type"] - return unless page_drop.author["name"] - return nil if author_type && !VALID_AUTHOR_TYPES.include?(author_type) + + author_type = page_drop.author["type"] + return if author_type && !VALID_AUTHOR_TYPES.include?(author_type) { "@type" => author_type || "Person",