Skip to content

Commit 274ea5d

Browse files
committed
Merge pull request #3 from benbalter/valid-html
Output valid html
2 parents 20b5789 + 2969a52 commit 274ea5d

File tree

8 files changed

+52
-6
lines changed

8 files changed

+52
-6
lines changed

jekyll-seo-tag.gemspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ Gem::Specification.new do |spec|
2828
spec.add_development_dependency "bundler", "~> 1.10"
2929
spec.add_development_dependency "rake", "~> 10.0"
3030
spec.add_development_dependency "rspec", "~> 3.3"
31+
spec.add_development_dependency "html-proofer", "~> 2.5"
32+
3133
end

lib/template.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
{% endif %}
1919
{% endif %}
2020
{% if seo_title %}
21-
{% assign seo_title = seo_title | escape | markdownify | strip_html | strip_newlines %}
21+
{% assign seo_title = seo_title | markdownify | strip_html | strip_newlines | escape_once %}
2222
{% endif %}
2323

2424
{% if page.description %}
@@ -27,7 +27,7 @@
2727
{% assign seo_description = site.description %}
2828
{% endif %}
2929
{% if seo_description %}
30-
{% assign seo_description = seo_description | escape | markdownify | strip_html | strip_newlines %}
30+
{% assign seo_description = seo_description | markdownify | strip_html | strip_newlines | escape_once %}
3131
{% endif %}
3232

3333
{% if seo_title %}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<html>
2+
<head>
3+
{% seo %}
4+
</head>
5+
<body>
6+
{{ content }}
7+
</body>
8+
</html>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Some "post" & a test
3+
description: A post
4+
layout: default
5+
---
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
layout: default
3+
---

spec/fixtures/page.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
---
2+
title: blah "blah" & blah
3+
description: Some description
4+
layout: default
25
---
36

47
# Test

spec/jekyll_seo_tag_spec.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
subject { Jekyll::SeoTag.new("seo", nil, nil) }
66

7+
before do
8+
Jekyll.logger.log_level = :error
9+
end
10+
711
it "builds" do
812
expect(subject.render(context)).to match(/Jekyll SEO tag/i)
913
end
@@ -29,9 +33,9 @@
2933
end
3034

3135
it "escapes titles" do
32-
site = site({"title" => "Jekyll & Hyde"})
36+
site = site({"title" => 'Jekyll & "Hyde"'})
3337
context = context({ :site => site })
34-
expect(subject.render(context)).to match(/<title>Jekyll &amp; Hyde<\/title>/)
38+
expect(subject.render(context)).to match(/<title>Jekyll &amp; Hyde<\/title>/)
3539
end
3640

3741
it "uses the page description" do
@@ -135,4 +139,14 @@
135139
expected = /<meta property="og:image" content="http:\/\/foo.invalid\/foo.png" \/>/
136140
expect(subject.render(context)).to match(expected)
137141
end
142+
143+
it "outputs valid HTML" do
144+
site.process
145+
options = {
146+
:check_html => true,
147+
:checks_to_ignore => ["ScriptCheck", "LinkCheck", "ImageCheck"]
148+
}
149+
status = HTML::Proofer.new(dest_dir, options).run
150+
expect(status).to eql(true)
151+
end
138152
end

spec/spec_helper.rb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
22
require 'jekyll'
33
require 'jekyll-seo-tag'
4+
require 'html/proofer'
5+
6+
ENV["JEKYLL_LOG_LEVEL"] = "error"
7+
8+
def dest_dir
9+
File.expand_path("../tmp/dest", File.dirname(__FILE__))
10+
end
11+
12+
def source_dir
13+
File.expand_path("./fixtures", File.dirname(__FILE__))
14+
end
415

516
CONFIG_DEFAULTS = {
6-
"source" => File.expand_path("./fixtures", File.dirname(__FILE__)),
7-
"destination" => File.expand_path("../tmp/dest", File.dirname(__FILE__)),
17+
"source" => source_dir,
18+
"destination" => dest_dir,
819
"gems" => ["jekyll-seo-tag"]
920
}
1021

0 commit comments

Comments
 (0)