Merge pull request #249 from jekyll/strip-null-values

Strip null values from JSON-LD hash
This commit is contained in:
Ben Balter 2017-11-16 14:36:03 -05:00 committed by GitHub
commit 38b0fbd73a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View File

@ -73,6 +73,10 @@ module Jekyll
alias_method :mainEntityOfPage, :main_entity
private :main_entity
def to_json
to_h.reject { |_k, v| v.nil? }.to_json
end
private
attr_reader :page_drop

View File

@ -152,4 +152,12 @@ RSpec.describe Jekyll::SeoTag::JSONLDDrop do
expect(subject).to have_key("url")
expect(subject["url"]).to eql("/page.html")
end
context "with null values" do
let(:metadata) { {} }
it "does not return null values as json" do
expect(subject.to_json).to_not match(%r!:null!)
end
end
end

View File

@ -338,6 +338,10 @@ EOS
it "minifies JSON-LD" do
expect(output).to_not match(%r!{.*?\s.*?}!)
end
it "removes null values from JSON-LD" do
expect(output).to_not match(%r!:null!)
end
end
end