Skip to content

Commit 9cb1ad0

Browse files
author
Elias Fröhner
authored
Allow to set type for author (#427)
Merge pull request 427
1 parent 22a160c commit 9cb1ad0

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

lib/jekyll-seo-tag/json_ld_drop.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class JSONLDDrop < Jekyll::Drops::Drop
2121
private :logo
2222

2323
VALID_ENTITY_TYPES = %w(BlogPosting CreativeWork).freeze
24-
private_constant :VALID_ENTITY_TYPES
24+
VALID_AUTHOR_TYPES = %w(Organization Person).freeze
25+
private_constant :VALID_ENTITY_TYPES, :VALID_AUTHOR_TYPES
2526

2627
# page_drop should be an instance of Jekyll::SeoTag::Drop
2728
def initialize(page_drop)
@@ -38,8 +39,11 @@ def fallback_data
3839
def author
3940
return unless page_drop.author["name"]
4041

42+
author_type = page_drop.author["type"]
43+
return if author_type && !VALID_AUTHOR_TYPES.include?(author_type)
44+
4145
{
42-
"@type" => "Person",
46+
"@type" => author_type || "Person",
4347
"name" => page_drop.author["name"],
4448
}
4549
end

spec/jekyll_seo_tag/json_ld_drop_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,29 @@
7272
end
7373
end
7474
end
75+
76+
context "when type Organization" do
77+
let(:author) { { "name" => "organization", "type" => "Organization" } }
78+
79+
it "returns the author with type" do
80+
expect(subject).to have_key("author")
81+
expect(subject["author"]).to be_a(Hash)
82+
expect(subject["author"]).to have_key("@type")
83+
expect(subject["author"]["@type"]).to eql("Organization")
84+
expect(subject["author"]).to have_key("name")
85+
expect(subject["author"]["name"]).to be_a(String)
86+
expect(subject["author"]["name"]).to eql("organization")
87+
end
88+
end
89+
90+
context "when invalid type" do
91+
let(:author) { { "name" => "organization", "type" => "Invalid" } }
92+
93+
it "returns the author with type" do
94+
expect(subject).to have_key("author")
95+
expect(subject["author"]).to be nil
96+
end
97+
end
7598
end
7699

77100
context "image" do

0 commit comments

Comments
 (0)