add datePublished to JSON-LD schema

This commit is contained in:
Ben Balter 2017-04-10 09:58:41 -05:00
parent de12942f36
commit d2f053dd43
No known key found for this signature in database
GPG Key ID: DBB67C246AD356C4
4 changed files with 33 additions and 14 deletions

View File

@ -102,6 +102,10 @@ module Jekyll
end
end
def date_published
@date_published ||= filters.date_to_xmlschema(page["date"]) if page["date"]
end
def type
@type ||= begin
if page["seo"] && page["seo"]["type"]

View File

@ -4,18 +4,19 @@ module Jekyll
# A hash of instance methods => key in resulting JSON-LD hash
METHODS_KEYS = {
:json_context => "@context",
:type => "@type",
:name => "name",
:page_title => "headline",
:json_author => "author",
:image_path => "image",
:date_modified => "dateModified",
:description => "description",
:publisher => "publisher",
:main_entity => "mainEntityOfPage",
:links => "sameAs",
:canonical_url => "url",
:json_context => "@context",
:type => "@type",
:name => "name",
:page_title => "headline",
:json_author => "author",
:image_path => "image",
:date_published => "datePublished",
:date_modified => "dateModified",
:description => "description",
:publisher => "publisher",
:main_entity => "mainEntityOfPage",
:links => "sameAs",
:canonical_url => "url",
}.freeze
def json_ld

View File

@ -246,6 +246,15 @@ RSpec.describe Jekyll::SeoTag::Drop do
end
end
context "date published" do
let(:config) { { "timezone" => "America/New_York" } }
let(:page_meta) { { "date" => "2017-01-01" } }
it "uses page.date" do
expect(subject.date_published).to eql("2017-01-01T00:00:00-05:00")
end
end
context "date modified" do
let(:config) { { "timezone" => "America/New_York" } }

View File

@ -12,7 +12,7 @@ RSpec.describe Jekyll::SeoTag::JSONLD do
"description" => "description",
"seo" => {
"name" => "seo name",
"date_modified" => "2017-01-01",
"date_modified" => "2017-01-02",
"links" => %w(a b),
},
}
@ -62,9 +62,14 @@ RSpec.describe Jekyll::SeoTag::JSONLD do
expect(subject["image"]).to eql("/image")
end
it "returns the datePublished" do
expect(subject).to have_key("datePublished")
expect(subject["datePublished"]).to eql("2017-01-01T00:00:00-05:00")
end
it "returns the dateModified" do
expect(subject).to have_key("dateModified")
expect(subject["dateModified"]).to eql("2017-01-01T00:00:00-05:00")
expect(subject["dateModified"]).to eql("2017-01-02T00:00:00-05:00")
end
it "returns the description" do