Make <title> optional

This commit is contained in:
Pat Hawks 2016-01-12 23:09:28 -08:00
parent b8d9cc2932
commit 66384741c3
No known key found for this signature in database
GPG Key ID: F1746FF5F18B3D1B
3 changed files with 18 additions and 2 deletions

View File

@ -3,6 +3,13 @@ module Jekyll
attr_accessor :context
def initialize(_, markup, _)
super
@options = {
"title" => !(markup =~ /title\s*:\s*false/i)
}
end
def render(context)
@context = context
output = template.render!(payload, info)
@ -15,7 +22,8 @@ module Jekyll
def payload
{
"page" => context.registers[:page],
"site" => context.registers[:site].site_payload["site"]
"site" => context.registers[:site].site_payload["site"],
"seo" => @options
}
end

View File

@ -44,7 +44,7 @@
{% assign seo_description = seo_description | markdownify | strip_html | strip_newlines | escape_once %}
{% endif %}
{% if seo_title %}
{% if seo_title and seo.title %}
<title>{{ seo_title }}</title>
{% endif %}

View File

@ -166,6 +166,14 @@ describe Jekyll::SeoTag do
expect(subject.render(context)).to match(expected)
end
it "does not output a <title> tag if title:false" do
site = site({"name" => "Site Name", "title" => "Site Title" })
context = context({ :site => site })
output = Liquid::Template.parse("{% seo title:false %}").render!(context, {})
expected = %r!<title>!
expect(output).not_to match(expected)
end
it "outputs valid HTML" do
site.process
options = {