Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strip null values from JSON-LD hash #249

Merged
merged 2 commits into from
Nov 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/jekyll-seo-tag/json_ld_drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ def main_entity
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,12 @@
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
4 changes: 4 additions & 0 deletions spec/jekyll_seo_tag_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@
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

Expand Down