Merge pull request #3 from benbalter/valid-html

Output valid html
This commit is contained in:
Ben Balter 2015-10-31 14:06:38 -04:00
commit 274ea5d0e9
8 changed files with 52 additions and 6 deletions

View File

@ -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

View File

@ -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 %}

8
spec/fixtures/_layouts/default.html vendored Normal file
View File

@ -0,0 +1,8 @@
<html>
<head>
{% seo %}
</head>
<body>
{{ content }}
</body>
</html>

View File

@ -0,0 +1,5 @@
---
title: Some "post" & a test
description: A post
layout: default
---

View File

@ -0,0 +1,3 @@
---
layout: default
---

View File

@ -1,4 +1,7 @@
---
title: blah "blah" & blah
description: Some description
layout: default
---
# Test

View File

@ -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(/<title>Jekyll &amp; Hyde<\/title>/)
expect(subject.render(context)).to match(/<title>Jekyll &amp; 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

View File

@ -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"]
}