diff --git a/README.md b/README.md
index 9e5b38d..661db9b 100644
--- a/README.md
+++ b/README.md
@@ -82,6 +82,14 @@ The SEO tag will respect the following YAML front matter if included in a post,
* `image` - Relative URL to an image associated with the post, page, or document (e.g., `assets/page-pic.jpg`)
* `author` - Page-, post-, or document-specific author information (see below)
+### Disabling `
` output
+
+Jekyll SEO Tag is designed to implement SEO best practices by default. If for some reason, you don't want the plugin to output `` tags on each page, simply invoke the plugin within your template like so:
+
+```
+{% seo title=false %}
+```
+
### Author information
Author information is used to propagate the `creator` field of Twitter summary cards. This is should be an author-specific, not site-wide Twitter handle (the site-wide username be stored as `site.twitter.username`).
diff --git a/lib/jekyll-seo-tag.rb b/lib/jekyll-seo-tag.rb
index c2e443f..b89f242 100644
--- a/lib/jekyll-seo-tag.rb
+++ b/lib/jekyll-seo-tag.rb
@@ -6,23 +6,37 @@ module Jekyll
MINIFY_REGEX = /(>\n|[%}]})\s+(<|{[{%])/
+ def initialize(_tag_name, text, _tokens)
+ super
+ @text = text
+ end
+
def render(context)
@context = context
- output = template.render!(payload, info)
-
- output
+ template.render!(payload, info)
end
private
+ def options
+ {
+ 'version' => VERSION,
+ 'title' => title?
+ }
+ end
+
def payload
{
- 'seo_tag' => { 'version' => VERSION },
'page' => context.registers[:page],
- 'site' => context.registers[:site].site_payload['site']
+ 'site' => context.registers[:site].site_payload['site'],
+ 'seo_tag' => options
}
end
+ def title?
+ !(@text =~ /title=false/i)
+ end
+
def info
{
registers: context.registers,
diff --git a/lib/template.html b/lib/template.html
index ee82f4c..8191b3f 100644
--- a/lib/template.html
+++ b/lib/template.html
@@ -53,7 +53,7 @@
{% assign seo_author_twitter = seo_author_twitter | replace:"@","" %}
{% endif %}
-{% if seo_title %}
+{% if seo_tag.title and seo_title %}
{{ seo_title }}
{% endif %}
diff --git a/spec/jekyll_seo_tag_spec.rb b/spec/jekyll_seo_tag_spec.rb
index 2605bc7..1753804 100644
--- a/spec/jekyll_seo_tag_spec.rb
+++ b/spec/jekyll_seo_tag_spec.rb
@@ -1,13 +1,14 @@
require 'spec_helper'
describe Jekyll::SeoTag do
- subject { Jekyll::SeoTag.parse('seo', nil, nil, nil) }
- let(:page) { make_page }
- let(:site) { make_site }
- let(:post) { make_post }
- let(:context) { make_context(page: page, site: site) }
- let(:output) { subject.render(context) }
- let(:json) { output.match(%r{}m)[1] }
+ let(:page) { make_page }
+ let(:site) { make_site }
+ let(:post) { make_post }
+ let(:context) { make_context(page: page, site: site) }
+ let(:tag) { 'seo' }
+ let(:text) { '' }
+ let(:output) { Liquid::Template.parse("{% #{tag} #{text} %}").render!(context, {}) }
+ let(:json) { output.match(%r{}m)[1] }
let(:json_data) { JSON.parse(json) }
before do
@@ -100,6 +101,7 @@ describe Jekyll::SeoTag do
context 'with site.baseurl' do
let(:site) { make_site('url' => 'http://example.invalid', 'baseurl' => '/foo') }
+
it 'uses baseurl to build the seo url' do
expected = %r{}
expect(output).to match(expected)
@@ -278,6 +280,14 @@ describe Jekyll::SeoTag do
end
end
+ context 'with title=false' do
+ let(:text) { 'title=false' }
+
+ it 'does not output a tag' do
+ expect(output).not_to match(//)
+ end
+ end
+
it 'outputs valid HTML' do
site.process
options = {