Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow to set type for author #427

Merged
merged 2 commits into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/jekyll-seo-tag/json_ld_drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class JSONLDDrop < Jekyll::Drops::Drop
private :logo

VALID_ENTITY_TYPES = %w(BlogPosting CreativeWork).freeze
private_constant :VALID_ENTITY_TYPES
VALID_AUTHOR_TYPES = %w(Organization Person).freeze
private_constant :VALID_ENTITY_TYPES, :VALID_AUTHOR_TYPES

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

author_type = page_drop.author["type"]
return if author_type && !VALID_AUTHOR_TYPES.include?(author_type)

{
"@type" => "Person",
"@type" => author_type || "Person",
"name" => page_drop.author["name"],
}
end
Expand Down
23 changes: 23 additions & 0 deletions spec/jekyll_seo_tag/json_ld_drop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down