From 2969a521f5fe4572f10625d7c617f58f32a72caf Mon Sep 17 00:00:00 2001 From: Ben Balter Date: Sat, 31 Oct 2015 14:05:19 -0400 Subject: [PATCH] output valid html --- jekyll-seo-tag.gemspec | 2 ++ lib/template.html | 4 ++-- spec/fixtures/_layouts/default.html | 8 ++++++++ spec/fixtures/_posts/2015-01-01-post.md | 5 +++++ spec/fixtures/_posts/2015-01-02-other-post.md | 3 +++ spec/fixtures/page.md | 3 +++ spec/jekyll_seo_tag_spec.rb | 18 ++++++++++++++++-- spec/spec_helper.rb | 15 +++++++++++++-- 8 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 spec/fixtures/_layouts/default.html diff --git a/jekyll-seo-tag.gemspec b/jekyll-seo-tag.gemspec index d525711..57f285e 100644 --- a/jekyll-seo-tag.gemspec +++ b/jekyll-seo-tag.gemspec @@ -28,4 +28,6 @@ Gem::Specification.new do |spec| spec.add_development_dependency "bundler", "~> 1.10" spec.add_development_dependency "rake", "~> 10.0" spec.add_development_dependency "rspec", "~> 3.3" + spec.add_development_dependency "html-proofer", "~> 2.5" + end diff --git a/lib/template.html b/lib/template.html index 40fe508..1366740 100644 --- a/lib/template.html +++ b/lib/template.html @@ -18,7 +18,7 @@ {% endif %} {% endif %} {% if seo_title %} - {% assign seo_title = seo_title | escape | markdownify | strip_html | strip_newlines %} + {% assign seo_title = seo_title | markdownify | strip_html | strip_newlines | escape_once %} {% endif %} {% if page.description %} @@ -27,7 +27,7 @@ {% assign seo_description = site.description %} {% endif %} {% if seo_description %} - {% assign seo_description = seo_description | escape | markdownify | strip_html | strip_newlines %} + {% assign seo_description = seo_description | markdownify | strip_html | strip_newlines | escape_once %} {% endif %} {% if seo_title %} diff --git a/spec/fixtures/_layouts/default.html b/spec/fixtures/_layouts/default.html new file mode 100644 index 0000000..b7afb8d --- /dev/null +++ b/spec/fixtures/_layouts/default.html @@ -0,0 +1,8 @@ + + + {% seo %} + + + {{ content }} + + diff --git a/spec/fixtures/_posts/2015-01-01-post.md b/spec/fixtures/_posts/2015-01-01-post.md index e69de29..bd3048e 100644 --- a/spec/fixtures/_posts/2015-01-01-post.md +++ b/spec/fixtures/_posts/2015-01-01-post.md @@ -0,0 +1,5 @@ +--- +title: Some "post" & a test +description: A post +layout: default +--- diff --git a/spec/fixtures/_posts/2015-01-02-other-post.md b/spec/fixtures/_posts/2015-01-02-other-post.md index e69de29..0d6905d 100644 --- a/spec/fixtures/_posts/2015-01-02-other-post.md +++ b/spec/fixtures/_posts/2015-01-02-other-post.md @@ -0,0 +1,3 @@ +--- +layout: default +--- diff --git a/spec/fixtures/page.md b/spec/fixtures/page.md index ef355dc..ae4618b 100644 --- a/spec/fixtures/page.md +++ b/spec/fixtures/page.md @@ -1,4 +1,7 @@ --- +title: blah "blah" & blah +description: Some description +layout: default --- # Test diff --git a/spec/jekyll_seo_tag_spec.rb b/spec/jekyll_seo_tag_spec.rb index a4c5e7f..9f9d6fa 100644 --- a/spec/jekyll_seo_tag_spec.rb +++ b/spec/jekyll_seo_tag_spec.rb @@ -4,6 +4,10 @@ describe Jekyll::SeoTag do subject { Jekyll::SeoTag.new("seo", nil, nil) } + before do + Jekyll.logger.log_level = :error + end + it "builds" do expect(subject.render(context)).to match(/Jekyll SEO tag/i) end @@ -29,9 +33,9 @@ describe Jekyll::SeoTag do end it "escapes titles" do - site = site({"title" => "Jekyll & Hyde"}) + site = site({"title" => 'Jekyll & "Hyde"'}) context = context({ :site => site }) - expect(subject.render(context)).to match(/Jekyll & Hyde<\/title>/) + expect(subject.render(context)).to match(/<title>Jekyll & “Hyde”<\/title>/) end it "uses the page description" do @@ -135,4 +139,14 @@ describe Jekyll::SeoTag do expected = /<meta property="og:image" content="http:\/\/foo.invalid\/foo.png" \/>/ expect(subject.render(context)).to match(expected) end + + it "outputs valid HTML" do + site.process + options = { + :check_html => true, + :checks_to_ignore => ["ScriptCheck", "LinkCheck", "ImageCheck"] + } + status = HTML::Proofer.new(dest_dir, options).run + expect(status).to eql(true) + end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a9faba9..c6c2a77 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,10 +1,21 @@ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) require 'jekyll' require 'jekyll-seo-tag' +require 'html/proofer' + +ENV["JEKYLL_LOG_LEVEL"] = "error" + +def dest_dir + File.expand_path("../tmp/dest", File.dirname(__FILE__)) +end + +def source_dir + File.expand_path("./fixtures", File.dirname(__FILE__)) +end CONFIG_DEFAULTS = { - "source" => File.expand_path("./fixtures", File.dirname(__FILE__)), - "destination" => File.expand_path("../tmp/dest", File.dirname(__FILE__)), + "source" => source_dir, + "destination" => dest_dir, "gems" => ["jekyll-seo-tag"] }