-
-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pagination is very confusing. #455
Comments
hey @freshyill, I don't find a solution. I literally given up on it as you can find in some of the issues I posted, been asking quite a long time ago to no avail. I am reiterating my site in Gatsby but to be honest, has the same challenges as well (but at least I know its possible given others achieved it). |
I use the following for my pagination and that works perfectly fine. I don’t know how pagination aliases work but it could be that you need to access pagination:
data: collections.posts
size: 5
reverse: true {%- for post in pagination.items -%}
<article class="post">
<a href="{{ post.link }}">{{ post.data.title }}</a>
</article>
{%- endfor -%}
{% if pagination.pageLinks.length > 1 %}
<nav class="pagination">
{% if pagination.previousPageLink %}
<a class="pagination__item" href="{{ pagination.previousPageHref | url }}">Newer Articles</a>
{% else %}
<span class="pagination__item">Newer Articles</span>
{% endif %}
{% if pagination.nextPageLink %}
<a class="pagination__item" href="{{ pagination.nextPageHref | url }}">Older Articles</a>
{% else %}
<span class="pagination__item">Older Articles</span>
{% endif %}
</nav>
{% endif %} |
@kleinfreund Your code works for me, just like all the other examples work. When I specify Can you tell me how you generate the actual pages? |
@ajmalafif Thanks for checking back in! Hopefully we can both find a resolution soon! |
@freshyill One requirement I haven’t mentioned: You need to have documents that are actually part of the collections I have a directory called
{
"tags": [
"posts"
]
} For me, all posts are part of that collection now and are built into a paginated blog index. No additional steps are necessary for me. I think your case would benefit from a test repository with which we can reporduce this issue. |
@kleinfreund I do have that as well. All of this is based on the eleventy-netlify-boilerplate, and I haven't really done anything at all to the structure of things yet. I'll try to put up a repo tonight. |
Please run DEBUG=Eleventy* eleventy ... or like this for a local installation of Eleventy: DEBUG=Eleventy* ./node_modules/@11ty/eleventy/cmd.js (These commands work in a terminal on Linux or macOS. In Windows, they would look different.) This will print a lot of debugging information. I’m interested in lines starting with this string:
In particular, yours should contain one like this:
(That’s what https://github.com/danurbanowicz/eleventy-netlify-boilerplate produces if freshly cloned) Note that the collection is called |
@kleinfreund I've determined that part of my issue is due to slugs The slug filter apparently doesn't strip a lot of characters, including apostrophes, exclamation marks, and periods(see #278). I implemented the slugify filter on #278 and now However, it still isn't properly generating the paginated blog pages or the pagination links. My main blog page compiles incorrectly, apparently because of something with the content, but it's inconsistent from one rebuild to the next. I'll ignore this for now and give the content a closer look soon separately. The blog/1, blog/2, etc. pages aren't generated at all. Can you see anything wrong with this? ---
layout: layouts/base.njk
section: blog
permalink: blog/{% if pagination.pageNumber > 0 %}page-{{ pagination.pageNumber }}/{% endif %}index.html
pagination:
data: collections.posts
size: 25
reverse: true
---
<article class="article article--index">
<div class="article__inner">
<h1>{{ title }}</h1>
{{ layoutContent | safe }}
</div>
</article>
{%- for post in pagination.items -%}
<article class="post">
<a href="{{ post.url }}">{{ post.data.title }}</a>
</article>
{%- endfor -%}
<pre>{{ pagination.previousPageHref | url }}{{ pagination.nextPageHref | url }}</pre>
{% if pagination.pageLinks.length > 1 %}
<nav class="pagination">
{% if pagination.previousPageLink %}
<a class="pagination__item" href="{{ pagination.previousPageHref | url }}">Newer Articles</a>
{% else %}
<span class="pagination__item">Newer Articles</span>
{% endif %}
{% if pagination.nextPageLink %}
<a class="pagination__item" href="{{ pagination.nextPageHref | url }}">Older Articles</a>
{% else %}
<span class="pagination__item">Older Articles</span>
{% endif %}
</nav>
{% endif %} |
The template itself looks fine to me. However, I’m curious as to the front matter’s Let’s go step by step. Have you run the command I posted? In particular, I want to know how many documents Eleventy thinks are in you collection. Can you post the output, please? |
cross-env package helps to run scripts that set and use environment variables, across platforms. Have been using it for running Eleventy on a local Windows machine. More details about cross-platform configuration from: josephdyer/skeleventy#2 (comment) |
@kleinfreund I believe that's taken from the docs. I had originally had |
Correction, the permalink pattern is not from the docs, it's from here: #76 (comment) |
Sorry I missed your comment with the debug instructions. The debug gives me this: 391 is the correct number of posts, for what it's worth. |
A detail I noticed from the debug: It's writing It seems like I have something just slightly off. Instead of getting I sort of suspect that my rendering errors are actually due to this overwriting. I don't know the specifics of how Node overwrites files, but it seems plausible based on what it actually looks like. |
If
You mentioned using |
For what it's worth, I used the slug in the permalink. I believe the issue there was that I had multiple posts that generated the same permalink… which ended up causing issues that affected how size was handled. It doesn't really matter. At any rate, I improved the post permalink structure and that part is fine now. I just got this sorted out. I do think the docs are a bit unclear and could probably benefit from some more real-world examples. As they are now, seem a little too simplified. Most people probably aren't defining data in the front matter and looping over that for pagination. I think I got hung up on the fact that the Here's roughly what I ended up with. blog.njk:---
layout: base
section: blog
pagination:
data: collections.post
size: 6
alias: postslist
---
{% for post in postslist | reverse %}
{% include "components/teaser.njk" %}
{% endfor %} blog.md---
layout: blog
title: Archive
tags:
- nav
- footnav
navtitle: Archive
date: 2019-01-11
permalink: archive/{% if pagination.pageNumber > 0 %}{{ pagination.pageNumber }}/{% endif %}index.html
---
… page content… This gives me |
We battled with this for weeks and i ended up finally coming up with this @freshyill
|
@zachleat I need to know how to paginate the tags as well as the entire post collection? any direction?? |
Here's how I solved this issue, pretty hacky but it works!
|
Hey @ajmalafif and @freshyill, {%- for pageUrl in pagination.hrefs %}
{%- set isCurrentPage = pagination.pageNumber == loop.index0 -%}
{%- if isCurrentPage %}<strong>{%- endif %}
{%- if isCurrentPage
or loop.first
or loop.last
or pagination.pageNumber in [loop.index0-1, loop.index0+1] -%}
{%- if loop.last and pagination.pageNumber < (loop.length - 3) -%}
...
{%- endif -%}
<a href="{{ pageUrl }}">{{ loop.index }}</a>
{%- if loop.first and pagination.pageNumber > 2 -%}
...
{%- endif -%}
{%- endif -%}
{%- if isCurrentPage %}</strong>{%- endif %}
{%- endfor %} I don't have many posts yet so the navigation window is only 3 pages wide. To make it 5 pages wide, change
Style separately; you might have to deal with whitespace differently since I wrote it within a markdown file. |
I agree, the pagination is so confusing I'm dumping all of my post by using |
I'm finding pagination to be very confusing with Eleventy. There's two parts to this that I see:
Breaking list up into pages:
It sort of works, but…
size
mean? I have absolutely no idea. When I specify1
, nothing happens. When I specify25
, I get 18 results, offset by 18. I'm so confused./blog/2
,/blog/3
, etc. Granted, this code doesn't look like it should, but what I pasted above is a variation on the same code I see over and over again, including in the docs. What code would produce the actual paginated pages?Pagination element
In #345, @ajmalafif asked about how to create an actual pagination element, which is definitely one part of this.
5, If it's not possible, can someone share something similar? How close to this can you get?
@ajmalafif did you ever find a solution?
The text was updated successfully, but these errors were encountered: