This commit is contained in:
Benji 2021-11-30 17:23:16 -08:00 committed by GitHub
commit 0bcbff61aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 18 deletions

View File

@ -67,6 +67,7 @@ module Jekyll
output = {
"@type" => "Organization",
"url" => page_drop.canonical_url,
"logo" => {
"@type" => "ImageObject",
"url" => logo,
@ -88,7 +89,22 @@ module Jekyll
private :main_entity
def to_json
to_h.compact.to_json
graph = to_h.compact
# assign publisher and remove it from the array
publisher = graph["publisher"] || nil
graph.delete("publisher")
updated_graph = {
"@context" => "https://schema.org",
"@graph" => [graph],
}
if publisher
updated_graph["@graph"] << publisher
end
# .to_json for the win
updated_graph.to_json
end
private

View File

@ -237,7 +237,7 @@ RSpec.describe Jekyll::SeoTag do
let(:site) { make_site("logo" => "/logo.png", "url" => "http://example.invalid") }
it "outputs the logo" do
expect(json_data["publisher"]["logo"]["url"]).to eql("http://example.invalid/logo.png")
expect(json_data["@graph"][1]["logo"]["url"]).to eql("http://example.invalid/logo.png")
end
end
@ -245,7 +245,7 @@ RSpec.describe Jekyll::SeoTag do
let(:site) { make_site("logo" => "http://cdn.example.invalid/logo.png", "url" => "http://example.invalid") }
it "outputs the logo" do
expect(json_data["publisher"]["logo"]["url"]).to eql("http://cdn.example.invalid/logo.png")
expect(json_data["@graph"][1]["logo"]["url"]).to eql("http://cdn.example.invalid/logo.png")
end
end
@ -253,7 +253,7 @@ RSpec.describe Jekyll::SeoTag do
let(:site) { make_site("logo" => "http://cdn.example.invalid/logo.png", "url" => "http://example.invalid", "author" => "Mr. Foo") }
it "outputs the author" do
expect(json_data["publisher"]["name"]).to eql("Mr. Foo")
expect(json_data["@graph"][1]["name"]).to eql("Mr. Foo")
end
end
@ -262,12 +262,12 @@ RSpec.describe Jekyll::SeoTag do
let(:page) { make_post("author" => "Mr. Foo") }
it "outputs the author" do
expect(json_data["author"]["@type"]).to eql("Person")
expect(json_data["author"]["name"]).to eql("Mr. Foo")
expect(json_data["@graph"][0]["author"]["@type"]).to eql("Person")
expect(json_data["@graph"][0]["author"]["name"]).to eql("Mr. Foo")
end
it "outputs the publisher author" do
expect(json_data["publisher"]["name"]).to eql("Mr. Foo")
expect(json_data["@graph"][1]["name"]).to eql("Mr. Foo")
end
end
@ -276,8 +276,8 @@ RSpec.describe Jekyll::SeoTag do
let(:page) { make_post("seo" => { "type" => "BlogPosting" }, "permalink" => "/foo/") }
it "outputs the mainEntityOfPage" do
expect(json_data["mainEntityOfPage"]["@type"]).to eql("WebPage")
expect(json_data["mainEntityOfPage"]["@id"]).to eql("http://example.invalid/foo/")
expect(json_data["@graph"][0]["mainEntityOfPage"]["@type"]).to eql("WebPage")
expect(json_data["@graph"][0]["mainEntityOfPage"]["@id"]).to eql("http://example.invalid/foo/")
end
end
@ -286,8 +286,8 @@ RSpec.describe Jekyll::SeoTag do
let(:page) { make_post("seo" => { "type" => "CreativeWork" }, "permalink" => "/foo/") }
it "outputs the mainEntityOfPage" do
expect(json_data["mainEntityOfPage"]["@type"]).to eql("WebPage")
expect(json_data["mainEntityOfPage"]["@id"]).to eql("http://example.invalid/foo/")
expect(json_data["@graph"][0]["mainEntityOfPage"]["@type"]).to eql("WebPage")
expect(json_data["@graph"][0]["mainEntityOfPage"]["@id"]).to eql("http://example.invalid/foo/")
end
end
@ -331,9 +331,9 @@ RSpec.describe Jekyll::SeoTag do
expected = %r!<meta property="og:type" content="article" />!
expect(output).to match(expected)
expect(json_data["headline"]).to eql("post")
expect(json_data["description"]).to eql("description")
expect(json_data["image"]).to eql("http://example.invalid/img.png")
expect(json_data["@graph"][0]["headline"]).to eql("post")
expect(json_data["@graph"][0]["description"]).to eql("description")
expect(json_data["@graph"][0]["image"]).to eql("http://example.invalid/img.png")
end
it "minifies JSON-LD" do
@ -552,9 +552,10 @@ RSpec.describe Jekyll::SeoTag do
end
it "outputs social meta" do
expect(json_data["@type"]).to eql("person")
expect(json_data["name"]).to eql("Ben")
expect(json_data["sameAs"]).to eql(links)
# binding.pry
expect(json_data["@graph"][0]["@type"]).to eql("person")
expect(json_data["@graph"][0]["name"]).to eql("Ben")
expect(json_data["@graph"][0]["sameAs"]).to eql(links)
end
end
@ -562,7 +563,7 @@ RSpec.describe Jekyll::SeoTag do
let(:meta) { { "permalink" => "/about/" } }
it "outputs sameAs links" do
expect(json_data["sameAs"]).to eql(links)
expect(json_data["@graph"][0]["sameAs"]).to eql(links)
end
end