paginator and trail don't produce the same URLs
Config:
pagination:
enabled: true
per_page: 10
permalink: '/page/:num'
title: ':title - page :num'
trail:
before: 2
after: 2
Input:
---
pagination:
enabled: true
category: blog
---
{% if paginator.total_pages > 1 %}
<div class="pagination">
{% if paginator.previous_page %}
<a href="{{ paginator.previous_page_path }}">Previous</a>
{% endif %}
{% if paginator.page_trail %}
{% for trail in paginator.page_trail %}
{% if trail.num == paginator.page %}
<span>{{ trail.num }}</span>
{% else %}
<a href="{{ trail.path }}">{{ trail.num }}</a>
{% endif %}
{% endfor %}
{% endif %}
{% if paginator.next_page %}
<a href="{{ paginator.next_page_path }}">Next</a>
{% endif %}
</div>
{% endif %}
Output:
<div class="pagination">
<span>1</span>
<a href="/blog/page/2index">2</a>
<a href="/blog/page/3index">3</a>
<a href="/blog/page/4index">4</a>
<a href="/blog/page/2">Next</a>
</div>
You can see "Next" points to /blog/page/2 like the permalink would suggest but the trails point to /blog/page/2index. Additionally, /blog/page/2 404's.
@heartsucker I understand this bug report. But may I know why you'd like to have a page generated at url /blog/page/2 instead of /blog/page/2/ or /blog/page/2/index.html
Just because I don't like my pages ending in .html and I have nginx set a default Content-Type: text/html.
Okay, I asked because from the source code below, it seems like extensionless urls were never part of the blueprint: https://github.com/sverrirs/jekyll-paginate-v2/blob/c657c5f8e02580a5e13f336d5c34fd4c81e212f7/lib/jekyll-paginate-v2/generator/paginator.rb#L30-L33 https://github.com/sverrirs/jekyll-paginate-v2/blob/c657c5f8e02580a5e13f336d5c34fd4c81e212f7/lib/jekyll-paginate-v2/generator/utils.rb#L127-L136
Ok so would that mean that in order for this to work, I'd have to end the pages with a / or not set the custom naming?
in order for this to work, I'd have to end the pages with a
/
Yes, that's correct.
I noticed this too when trying to migrate to this gem. I kept the solution I used with jekyll-paginate and I add the trailing slash myself. Note that in the header, the trailing slash is added properly.
I have the same problem, but I did not understand how to solve it: once the page paths were generated correctly, /page/2/index.html instead now it has been changed to /page/2index.html how can I restore it to the old method?
I have the same problem, but I did not understand how to solve it: once the page paths were generated correctly, /page/2/index.html instead now it has been changed to /page/2index.html how can I restore it to the old method?
ok fixed with custom indexpage:
pagination:
enabled: true
collection: blog
indexpage: '/index'
Could you please upgrade to https://rubygems.org/gems/jekyll-paginate-v2/versions/3.0.0 and test again for me?
Could you please upgrade to https://rubygems.org/gems/jekyll-paginate-v2/versions/3.0.0 and test again for me?
Tested, now working but the link of first page have two trailing slash
Page 1:
<ul class="pager" style="clear: both;">
<li class="selected">
<a href="/blog//index.html" title="Blog">1</a>
</li>
<li >
<a href="/blog/page/2/index" title="Blog - Page 2 of 2">2</a>
</li>
<li class="next">
<a href="/blog/page/2/index">Older Posts →</a>
</li>
</ul>
Page 2:
<ul class="pager" style="clear: both;">
<li class="previous">
<a href="/blog/index.html">← Newer Posts</a>
</li>
<li >
<a href="/blog//index.html" title="Blog">1</a>
</li>
<li >
<a href="/blog/page/2/index" title="Blog - Page 2 of 2">2</a>
</li>
</ul>
I see similar issues with discrepancies between paginator and page_trail, missing slashes and redundant index.html.
This is my _config.yml:
title: Your awesome title
email: [email protected]
future: true
plugins:
- jekyll-paginate-v2
pagination:
enabled: true
permalink: /page:num
per_page: 5
trail:
before: 2
after: 2
sass:
quiet_deps: true
index.md looks like this:
---
layout: home
permalink: /posts/
pagination:
enabled: true
---
There are enough posts to generate five pages, and _layouts/home.html looks like
<!DOCTYPE html>
<html>
<head><title></title></head>
<body>
<h1>Home page</h1>
{% for post in paginator.posts %}
<h2>{{ post.title }}</h2>
{% endfor %}
<p><code>paginator</code> values:</p>
<ul>
<li>First: <code>{{ paginator.first_page_path }}</code>
<li>Previous: <code>{{ paginator.previous_page_path }}</code>
<li>Current: <code>{{ paginator.page_path }}</code>
<li>Next: <code>{{ paginator.next_page_path }}</code>
<li>Last: <code>{{ paginator.last_page_path }}</code>
</ul>
<p><code>page_trail</code> values:</p>
<ul>
{% for trail in paginator.page_trail %}
<li>
<a href="{{ trail.path }}">{{ trail.num }}</a>: <code>{{ trail | jsonify }}</code>
</li>
{% endfor %}
</ul>
</body>
</html>
Now, for the three different options for pagination.permalink described here
https://github.com/sverrirs/jekyll-paginate-v2/blob/7bc2634c04c49120b674cc3506275f85c4389f5c/README-GENERATOR.md#L63-L65
I get the following results (I use no / before :num, but it makes no difference):
/page:num/
Generated pages:
posts/
├── index.html
├── page2
│ └── index.html
├── page3
│ └── index.html
├── page4
│ └── index.html
└── page5
└── index.html
✅ Looks as expected
paginator values:
- First:
/posts/ - Previous:
/posts/page2/ - Current:
/posts/page3/index.html - Next:
/posts/page4/ - Last:
/posts/page5/
:x: Redundant index.html for current page
page_trail values:
- 1:
{"num":1,"path":"/posts/index.html","title":"Your awesome title"} - 2:
{"num":2,"path":"/posts/page2/index.html","title":"Your awesome title - page 2"} - 3:
{"num":3,"path":"/posts/page3/index.html","title":"Your awesome title - page 3"} - 4:
{"num":4,"path":"/posts/page4/index.html","title":"Your awesome title - page 4"} - 5:
{"num":5,"path":"/posts/page5/index.html","title":"Your awesome title - page 5"}
:x: Redundant index.html for every path
/page:num.html
posts/
├── index.html
├── page2.html
├── page3.html
├── page4.html
└── page5.html
✅ Looks as expected
paginator values:
- First:
/posts/ - Previous:
/posts/page2.html - Current:
/posts/page3.html - Next:
/posts/page4.html - Last:
/posts/page5.html
✅ Looks as expected
page_trail values:
- 1:
{"num":1,"path":"/posts/index.html","title":"Your awesome title"} - 2:
{"num":2,"path":"/posts/page2.html","title":"Your awesome title - page 2"} - 3:
{"num":3,"path":"/posts/page3.html","title":"Your awesome title - page 3"} - 4:
{"num":4,"path":"/posts/page4.html","title":"Your awesome title - page 4"} - 5:
{"num":5,"path":"/posts/page5.html","title":"Your awesome title - page 5"}
:x: Discrepancy between path for first page in paginator and page_trail (trail has extra index.html)
/page:num
posts/
├── index.html
├── page2index.html
├── page3index.html
├── page4index.html
└── page5index.html
:x: Pages beyond the first one seem to miss a / before index.html
paginator values:
- First:
/posts/ - Previous:
/posts/page2 - Current:
/posts/page3index - Next:
/posts/page4 - Last:
/posts/page5
:x: Other than the first and current page, these are broken links
page_trail values:
- 1:
{"num":1,"path":"/posts/index.html","title":"Your awesome title"} - 2:
{"num":2,"path":"/posts/page2index","title":"Your awesome title - page 2"} - 3:
{"num":3,"path":"/posts/page3index","title":"Your awesome title - page 3"} - 4:
{"num":4,"path":"/posts/page4index","title":"Your awesome title - page 4"} - 5:
{"num":5,"path":"/posts/page5index","title":"Your awesome title - page 5"}
:x: Different from paginator, but no broken links
Differences between paginator and page_trail aren't a huge deal, though it would be nice to not have them, but the behaviour for /page:num seems buggy (and that's exactly the behaviour I'd like to have, with links like posts/, posts/page2/ etc.)
Gemfile
source "https://rubygems.org"
ruby "3.2.1"
gem "jekyll", "~> 4.3.2"
gem "jekyll-paginate-v2", "~> 3.0"
Gemfile.lock
GEM
remote: https://rubygems.org/
specs:
addressable (2.8.1)
public_suffix (>= 2.0.2, < 6.0)
colorator (1.1.0)
concurrent-ruby (1.2.2)
em-websocket (0.5.3)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0)
eventmachine (1.2.7)
ffi (1.15.5)
forwardable-extended (2.6.0)
google-protobuf (3.22.2-x86_64-linux)
http_parser.rb (0.8.0)
i18n (1.12.0)
concurrent-ruby (~> 1.0)
jekyll (4.3.2)
addressable (~> 2.4)
colorator (~> 1.0)
em-websocket (~> 0.5)
i18n (~> 1.0)
jekyll-sass-converter (>= 2.0, < 4.0)
jekyll-watch (~> 2.0)
kramdown (~> 2.3, >= 2.3.1)
kramdown-parser-gfm (~> 1.0)
liquid (~> 4.0)
mercenary (>= 0.3.6, < 0.5)
pathutil (~> 0.9)
rouge (>= 3.0, < 5.0)
safe_yaml (~> 1.0)
terminal-table (>= 1.8, < 4.0)
webrick (~> 1.7)
jekyll-paginate-v2 (3.0.0)
jekyll (>= 3.0, < 5.0)
jekyll-sass-converter (3.0.0)
sass-embedded (~> 1.54)
jekyll-watch (2.2.1)
listen (~> 3.0)
kramdown (2.4.0)
rexml
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
liquid (4.0.4)
listen (3.8.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
mercenary (0.4.0)
pathutil (0.16.2)
forwardable-extended (~> 2.6)
public_suffix (5.0.1)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rexml (3.2.5)
rouge (4.1.0)
safe_yaml (1.0.5)
sass-embedded (1.59.3-x86_64-linux-gnu)
google-protobuf (~> 3.21)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
unicode-display_width (2.4.2)
webrick (1.8.1)
PLATFORMS
x86_64-linux
DEPENDENCIES
jekyll (~> 4.3.2)
jekyll-paginate-v2 (~> 3.0)
RUBY VERSION
ruby 3.2.1p31
BUNDLED WITH
2.4.8