Merge pull request #324 from AlekseySpiridonov/add-custom-paginator-message

Merge pull request 324
This commit is contained in:
jekyllbot 2019-10-08 10:42:25 -04:00 committed by GitHub
commit 32ce8914f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 1 deletions

View File

@ -140,3 +140,17 @@ Which will generate following canonical_url:
```html
<link rel="canonical" href="https://example.com/title-of-your-post" />
```
### 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 `seo_paginator_message` key in your `_config.yml`.
For example:
```yml
seo_paginator_message: "%<current>s / %<total>s | "
```
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.

View File

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