Merge pull request #249 from jekyll/strip-null-values
Strip null values from JSON-LD hash
This commit is contained in:
commit
38b0fbd73a
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue