Adding possibility to change pagination message by config file

Default message can by overriten by "paginator_message" parameter in _config.yml
This commit is contained in:
Aleksey Spiridonov 2019-01-06 01:16:32 +04:00
parent bb04d06a3e
commit 39269edc33
5 changed files with 34 additions and 2 deletions

View File

@ -138,3 +138,12 @@ Which will generate following canonical_url:
```html
<link rel="canonical" href="http://yoursite.com/title-of-your-post" />
```
### Changing title message for paginated page
You can override default title message for paginated page from `Page %<current>s of %<total>s for ` to custom message by adding parameter to `_config.yml`.
For example:
```yml
paginator_message: "%<current>s / %<total>s |"
```
For key **paginator_message** please use string template with two variables `current` and `total`.

View File

@ -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"

View File

@ -189,8 +189,9 @@ module Jekyll
current = @context["paginator"]["page"]
total = @context["paginator"]["total_pages"]
paginator_message = site["paginator_message"] || "Page %<current>s of %<total>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

View File

@ -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" => "%<current>s of %<total>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

View File

@ -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