diff --git a/lib/jekyll-seo-tag/drop.rb b/lib/jekyll-seo-tag/drop.rb index 8e07d71..d5784d0 100644 --- a/lib/jekyll-seo-tag/drop.rb +++ b/lib/jekyll-seo-tag/drop.rb @@ -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"] diff --git a/lib/jekyll-seo-tag/json_ld.rb b/lib/jekyll-seo-tag/json_ld.rb index f33c59a..4439039 100644 --- a/lib/jekyll-seo-tag/json_ld.rb +++ b/lib/jekyll-seo-tag/json_ld.rb @@ -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 diff --git a/spec/jekyll_seo_tag/drop_spec.rb b/spec/jekyll_seo_tag/drop_spec.rb index d9ab962..678cfb4 100644 --- a/spec/jekyll_seo_tag/drop_spec.rb +++ b/spec/jekyll_seo_tag/drop_spec.rb @@ -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" } } diff --git a/spec/jekyll_seo_tag/json_ld_spec.rb b/spec/jekyll_seo_tag/json_ld_spec.rb index 58a6d9f..1b86945 100644 --- a/spec/jekyll_seo_tag/json_ld_spec.rb +++ b/spec/jekyll_seo_tag/json_ld_spec.rb @@ -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