From 39269edc33cbd6975b705290fadbd76cf2c60263 Mon Sep 17 00:00:00 2001 From: Aleksey Spiridonov Date: Sun, 6 Jan 2019 01:16:32 +0400 Subject: [PATCH 1/5] Adding possibility to change pagination message by config file Default message can by overriten by "paginator_message" parameter in _config.yml --- docs/advanced-usage.md | 9 +++++++++ jekyll-seo-tag.gemspec | 2 +- lib/jekyll-seo-tag/drop.rb | 3 ++- spec/jekyll_seo_tag/drop_spec.rb | 21 +++++++++++++++++++++ spec/spec_helper.rb | 1 + 5 files changed, 34 insertions(+), 2 deletions(-) diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index c2fbed5..13449b5 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -138,3 +138,12 @@ Which will generate following canonical_url: ```html ``` + +### Changing title message for paginated page + +You can override default title message for paginated page from `Page %s of %s for ` to custom message by adding parameter to `_config.yml`. +For example: +```yml +paginator_message: "%s / %s |" +``` +For key **paginator_message** please use string template with two variables `current` and `total`. \ No newline at end of file diff --git a/jekyll-seo-tag.gemspec b/jekyll-seo-tag.gemspec index ee00558..90d3fb6 100644 --- a/jekyll-seo-tag.gemspec +++ b/jekyll-seo-tag.gemspec @@ -29,7 +29,7 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] spec.add_dependency "jekyll", "~> 3.3" - spec.add_development_dependency "bundler", "~> 1.15" + spec.add_development_dependency "bundler" spec.add_development_dependency "html-proofer", "~> 3.7" spec.add_development_dependency "rspec", "~> 3.5" spec.add_development_dependency "rubocop-jekyll", "~> 0.4" diff --git a/lib/jekyll-seo-tag/drop.rb b/lib/jekyll-seo-tag/drop.rb index 354c07f..2aa10bd 100644 --- a/lib/jekyll-seo-tag/drop.rb +++ b/lib/jekyll-seo-tag/drop.rb @@ -189,8 +189,9 @@ module Jekyll current = @context["paginator"]["page"] total = @context["paginator"]["total_pages"] + paginator_message = site["paginator_message"] || "Page %s of %s for " - return "Page #{current} of #{total} for " if current > 1 + format(paginator_message, :current => current, :total => total) if current > 1 end attr_reader :context diff --git a/spec/jekyll_seo_tag/drop_spec.rb b/spec/jekyll_seo_tag/drop_spec.rb index 172f581..b4678d7 100644 --- a/spec/jekyll_seo_tag/drop_spec.rb +++ b/spec/jekyll_seo_tag/drop_spec.rb @@ -482,6 +482,27 @@ RSpec.describe Jekyll::SeoTag::Drop do end end + context "pagination" do + let(:context) do + make_context( + { :page => page, :site => site }, + "paginator" => { "page" => 2, "total_pages" => 10 } + ) + end + + it "render default pagination title" do + expect(subject.send(:page_number)).to eq("Page 2 of 10 for ") + end + + context "render custom pagination title" do + let(:config) { { "paginator_message" => "%s of %s" } } + + it "renders the correct page number" do + expect(subject.send(:page_number)).to eq("2 of 10") + end + end + end + it "exposes the JSON-LD drop" do expect(subject.json_ld).to be_a(Jekyll::SeoTag::JSONLDDrop) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 554ba2f..643a1dc 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,6 +4,7 @@ $LOAD_PATH.unshift File.expand_path("../lib", __dir__) require "jekyll" require "jekyll-seo-tag" require "html-proofer" +require "jekyll-paginate" # Monkey patch Jekyll::Drops::Drop so Rspec's `have_key` works as expected module Jekyll From d585dc34184c783d7f12982e96f36e46156c6e27 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Sun, 6 Jan 2019 11:49:21 +0530 Subject: [PATCH 2/5] Undo change outside the scope of this pull request --- jekyll-seo-tag.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jekyll-seo-tag.gemspec b/jekyll-seo-tag.gemspec index 90d3fb6..ee00558 100644 --- a/jekyll-seo-tag.gemspec +++ b/jekyll-seo-tag.gemspec @@ -29,7 +29,7 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] spec.add_dependency "jekyll", "~> 3.3" - spec.add_development_dependency "bundler" + spec.add_development_dependency "bundler", "~> 1.15" spec.add_development_dependency "html-proofer", "~> 3.7" spec.add_development_dependency "rspec", "~> 3.5" spec.add_development_dependency "rubocop-jekyll", "~> 0.4" From 9b1001eb62b106a92bae07e0cc820af67d6514b2 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Sun, 6 Jan 2019 11:50:03 +0530 Subject: [PATCH 3/5] undo unnecessary change --- spec/spec_helper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 643a1dc..554ba2f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,7 +4,6 @@ $LOAD_PATH.unshift File.expand_path("../lib", __dir__) require "jekyll" require "jekyll-seo-tag" require "html-proofer" -require "jekyll-paginate" # Monkey patch Jekyll::Drops::Drop so Rspec's `have_key` works as expected module Jekyll From 5aab527805be017c0beeec68a05cb16697a739b1 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Sun, 6 Jan 2019 12:05:30 +0530 Subject: [PATCH 4/5] Improve documentation for this enhancement --- docs/advanced-usage.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 13449b5..f03020d 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -139,11 +139,16 @@ Which will generate following canonical_url: ``` -### Changing title message for paginated page +### Customizing title modifier for paginated pages + +You can override the default title modifier for paginated pages from `Page %{current} of %{total} for ` to a string of your +choice by setting a `paginator_message` key in your `_config.yml`. -You can override default title message for paginated page from `Page %s of %s for ` to custom message by adding parameter to `_config.yml`. For example: + ```yml -paginator_message: "%s / %s |" +paginator_message: "%s / %s | " ``` -For key **paginator_message** please use string template with two variables `current` and `total`. \ No newline at end of file + +While the value can be any string text, we recommend using a Ruby string-template containing the variables `current` and `total` +similar to the example above, to incorporate the current page-number and total number of paginated pages in the title. From 8557598116111b440d26488a307da66d62a56f08 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Tue, 8 Jan 2019 20:27:50 +0530 Subject: [PATCH 5/5] prefix config key with 'seo_' to avoid conflicts --- docs/advanced-usage.md | 4 ++-- lib/jekyll-seo-tag/drop.rb | 2 +- spec/jekyll_seo_tag/drop_spec.rb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index f03020d..e93554f 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -142,12 +142,12 @@ Which will generate following canonical_url: ### Customizing title modifier for paginated pages You can override the default title modifier for paginated pages from `Page %{current} of %{total} for ` to a string of your -choice by setting a `paginator_message` key in your `_config.yml`. +choice by setting a `seo_paginator_message` key in your `_config.yml`. For example: ```yml -paginator_message: "%s / %s | " +seo_paginator_message: "%s / %s | " ``` While the value can be any string text, we recommend using a Ruby string-template containing the variables `current` and `total` diff --git a/lib/jekyll-seo-tag/drop.rb b/lib/jekyll-seo-tag/drop.rb index 2aa10bd..5ecbf7b 100644 --- a/lib/jekyll-seo-tag/drop.rb +++ b/lib/jekyll-seo-tag/drop.rb @@ -189,7 +189,7 @@ module Jekyll current = @context["paginator"]["page"] total = @context["paginator"]["total_pages"] - paginator_message = site["paginator_message"] || "Page %s of %s for " + paginator_message = site["seo_paginator_message"] || "Page %s of %s for " format(paginator_message, :current => current, :total => total) if current > 1 end diff --git a/spec/jekyll_seo_tag/drop_spec.rb b/spec/jekyll_seo_tag/drop_spec.rb index b4678d7..3ffbb6b 100644 --- a/spec/jekyll_seo_tag/drop_spec.rb +++ b/spec/jekyll_seo_tag/drop_spec.rb @@ -495,7 +495,7 @@ RSpec.describe Jekyll::SeoTag::Drop do end context "render custom pagination title" do - let(:config) { { "paginator_message" => "%s of %s" } } + let(:config) { { "seo_paginator_message" => "%s of %s" } } it "renders the correct page number" do expect(subject.send(:page_number)).to eq("2 of 10")