properly escape smart quotes in title and description
This commit is contained in:
parent
c255b5398d
commit
1567a53d4e
|
@ -5,7 +5,16 @@ module Jekyll
|
|||
|
||||
def render(context)
|
||||
@context = context
|
||||
Liquid::Template.parse(template_contents).render!(payload, info).gsub(/[\n\s]{2,}/, "\n")
|
||||
output = Liquid::Template.parse(template_contents).render!(payload, info)
|
||||
|
||||
# Minify
|
||||
output.gsub!(/[\n\s]{2,}/, "\n")
|
||||
|
||||
# Encode smart quotes. See https://github.com/benbalter/jekyll-seo-tag/pull/6
|
||||
output.gsub!("\u201c", "“")
|
||||
output.gsub!("\u201d", "”")
|
||||
|
||||
output
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
{% endif %}
|
||||
{% endif %}
|
||||
{% if seo_title %}
|
||||
{% assign seo_title = seo_title | escape | markdownify | strip_html | strip_newlines | replace:'"','"' | escape_once %}
|
||||
{% 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 | replace:'"','"' | escape_once %}
|
||||
{% assign seo_description = seo_description | markdownify | strip_html | strip_newlines | escape_once %}
|
||||
{% endif %}
|
||||
|
||||
{% if seo_title %}
|
||||
|
|
|
@ -35,13 +35,13 @@ describe Jekyll::SeoTag do
|
|||
it "escapes titles" do
|
||||
site = site({"title" => 'Jekyll & "Hyde"'})
|
||||
context = context({ :site => site })
|
||||
expect(subject.render(context)).to match(/<title>Jekyll & "Hyde"<\/title>/)
|
||||
expect(subject.render(context)).to match(/<title>Jekyll & “Hyde”<\/title>/)
|
||||
end
|
||||
|
||||
it "escapes descriptions" do
|
||||
site = site({"description" => 'Jekyll & "Hyde"'})
|
||||
context = context({ :site => site })
|
||||
expected = /<meta name="description" content="Jekyll & "Hyde"" \/>/
|
||||
expected = /<meta name="description" content="Jekyll & “Hyde”" \/>/
|
||||
expect(subject.render(context)).to match(expected)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue