From 220901c140d595963946750e932955ca2e8e9836 Mon Sep 17 00:00:00 2001 From: Todd Eichel Date: Wed, 11 May 2016 15:02:07 -0700 Subject: [PATCH 1/6] Different philosophy for rel prev/next links based on recommendations from Google. Details here: https://webmasters.googleblog.com/2011/09/pagination-with-relnext-and-relprev.html. This replaces the per-page prev/next links with general ones that will be output whenever there is a paginator with a previous or next page to show. --- README.md | 2 +- lib/jekyll-seo-tag.rb | 1 + lib/template.html | 13 ++++++------- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 132b651..996456d 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Jekyll SEO Tag adds the following meta tags to your site: * Pages title (with site title appended when available) * Page description * Canonical URL -* Next and previous URLs for posts +* Next and previous URLs on paginated pages * [JSON-LD Site and post metadata](https://developers.google.com/structured-data/) for richer indexing * [Open graph](http://ogp.me/) title, description, site title, and URL (for Facebook, LinkedIn, etc.) * [Twitter summary card](https://dev.twitter.com/cards/overview) metadata diff --git a/lib/jekyll-seo-tag.rb b/lib/jekyll-seo-tag.rb index 1e10877..1c98cde 100644 --- a/lib/jekyll-seo-tag.rb +++ b/lib/jekyll-seo-tag.rb @@ -30,6 +30,7 @@ module Jekyll { 'page' => context.registers[:page], 'site' => context.registers[:site].site_payload['site'], + 'paginator' => context['paginator'], 'seo_tag' => options } end diff --git a/lib/template.html b/lib/template.html index 59756a1..20d57b2 100644 --- a/lib/template.html +++ b/lib/template.html @@ -139,14 +139,13 @@ {% if page.date %} +{% endif %} - {% if page.next.url %} - - {% endif %} - - {% if page.previous.url %} - - {% endif %} +{% if paginator.previous_page %} + +{% endif %} +{% if paginator.next_page %} + {% endif %} {% if site.twitter %} From b55105813a35c0b760c45f553e22d4bbff7caf21 Mon Sep 17 00:00:00 2001 From: Todd Eichel Date: Fri, 27 May 2016 12:17:52 -0700 Subject: [PATCH 2/6] Move this individual spec up with other individual ones. --- spec/jekyll_seo_tag_spec.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/spec/jekyll_seo_tag_spec.rb b/spec/jekyll_seo_tag_spec.rb index 559d9fb..7f74c5c 100644 --- a/spec/jekyll_seo_tag_spec.rb +++ b/spec/jekyll_seo_tag_spec.rb @@ -24,6 +24,16 @@ describe Jekyll::SeoTag do expect(output).to match(/Jekyll SEO tag v#{version}/i) end + it 'outputs valid HTML' do + site.process + options = { + check_html: true, + checks_to_ignore: %w(ScriptCheck LinkCheck ImageCheck) + } + status = HTML::Proofer.new(dest_dir, options).run + expect(status).to eql(true) + end + context 'with page.title' do let(:page) { make_page('title' => 'foo') } @@ -433,14 +443,4 @@ EOS expect(output).not_to match(//) end end - - it 'outputs valid HTML' do - site.process - options = { - check_html: true, - checks_to_ignore: %w(ScriptCheck LinkCheck ImageCheck) - } - status = HTML::Proofer.new(dest_dir, options).run - expect(status).to eql(true) - end end From edd65c3f14cdf01963ff04f08ad9ca1282690302 Mon Sep 17 00:00:00 2001 From: Todd Eichel <todd@toddeichel.com> Date: Fri, 27 May 2016 14:59:39 -0700 Subject: [PATCH 3/6] Allow passing custom environments when making Liquid contexts for testing. Backwards-compatible with previous implementation. --- spec/spec_helper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4bf3092..a83c8fd 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -38,6 +38,6 @@ def make_site(options = {}) Jekyll::Site.new(config) end -def make_context(registers = {}) - Liquid::Context.new({}, {}, { site: site, page: page }.merge(registers)) +def make_context(registers = {}, environments: {}) + Liquid::Context.new(environments, {}, { site: site, page: page }.merge(registers)) end From 7fefcdef3fa840778ef8d74d98bf434c4acb5c25 Mon Sep 17 00:00:00 2001 From: Todd Eichel <todd@toddeichel.com> Date: Fri, 27 May 2016 15:00:15 -0700 Subject: [PATCH 4/6] Specs for pagination. --- spec/jekyll_seo_tag_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/jekyll_seo_tag_spec.rb b/spec/jekyll_seo_tag_spec.rb index 7f74c5c..fe6bc2a 100644 --- a/spec/jekyll_seo_tag_spec.rb +++ b/spec/jekyll_seo_tag_spec.rb @@ -10,6 +10,7 @@ describe Jekyll::SeoTag do let(:output) { Liquid::Template.parse("{% #{tag} #{text} %}").render!(context, {}) } let(:json) { output.match(%r{<script type=\"application/ld\+json\">(.*)</script>}m)[1] } let(:json_data) { JSON.parse(json) } + let(:paginator) { { 'previous_page' => true, 'previous_page_path' => 'foo', 'next_page' => true, 'next_page_path' => 'bar' } } before do Jekyll.logger.log_level = :error @@ -443,4 +444,13 @@ EOS expect(output).not_to match(/<title>/) end end + + context 'with pagination' do + let(:context) { make_context(environments: { 'paginator' => paginator }) } + + it 'outputs pagination links' do + expect(output).to match(%r{<link rel="prev" href="foo">}) + expect(output).to match(%r{<link rel="next" href="bar">}) + end + end end From c58f44d9a352ba5c51cb9d828a0c14f1542eb78d Mon Sep 17 00:00:00 2001 From: Todd Eichel <todd@toddeichel.com> Date: Fri, 27 May 2016 15:04:56 -0700 Subject: [PATCH 5/6] Oops, that wasn't as backwards compatible as I thought. --- spec/jekyll_seo_tag_spec.rb | 2 +- spec/spec_helper.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/jekyll_seo_tag_spec.rb b/spec/jekyll_seo_tag_spec.rb index fe6bc2a..c0b196f 100644 --- a/spec/jekyll_seo_tag_spec.rb +++ b/spec/jekyll_seo_tag_spec.rb @@ -446,7 +446,7 @@ EOS end context 'with pagination' do - let(:context) { make_context(environments: { 'paginator' => paginator }) } + let(:context) { make_context({}, { 'paginator' => paginator }) } it 'outputs pagination links' do expect(output).to match(%r{<link rel="prev" href="foo">}) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a83c8fd..d443b3e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -38,6 +38,6 @@ def make_site(options = {}) Jekyll::Site.new(config) end -def make_context(registers = {}, environments: {}) +def make_context(registers = {}, environments = {}) Liquid::Context.new(environments, {}, { site: site, page: page }.merge(registers)) end From 73608f8ca1c37afb0a4376a01a2d6885b9dfd1d3 Mon Sep 17 00:00:00 2001 From: Todd Eichel <todd@toddeichel.com> Date: Fri, 27 May 2016 15:09:59 -0700 Subject: [PATCH 6/6] Appease rubocop. --- spec/jekyll_seo_tag_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/jekyll_seo_tag_spec.rb b/spec/jekyll_seo_tag_spec.rb index c0b196f..63922aa 100644 --- a/spec/jekyll_seo_tag_spec.rb +++ b/spec/jekyll_seo_tag_spec.rb @@ -446,11 +446,11 @@ EOS end context 'with pagination' do - let(:context) { make_context({}, { 'paginator' => paginator }) } + let(:context) { make_context({}, 'paginator' => paginator) } it 'outputs pagination links' do - expect(output).to match(%r{<link rel="prev" href="foo">}) - expect(output).to match(%r{<link rel="next" href="bar">}) + expect(output).to match(/<link rel="prev" href="foo">/) + expect(output).to match(/<link rel="next" href="bar">/) end end end