I used jekyll-archives
to create archive pages. Whilst I managed to get the plugin to work, I was unable to find a solution to paginate the archives, so I’m now using just jekyll-paginate-v2
to achieve this objective (I need the archived posts to be paginated.).
The problem is that I’m not sure how to paginate posts based on years. I know paginate-v2 can paginate tags, categories, collections, etc. but I’m not sure how it can paginate years.
I have some 80 posts in 2021, and I want to create a paginated archive containing posts only from 2021. Below is my file structure in which index.html inside the 2021 folder is where I plan to create the archive.
|- _posts
|- blogs
| - archives
| - 2021
| - index.html
I tried the following code and a few others including putting an if outside/inside the for loop, but none of these worked:
{% assign year = post.date | date: "%Y" %}
{% assign posts = paginator.posts | where_exp: "post", "year == '2021'" %}
{% for post in posts %}
<div class="article-template" style="min-height: 100px;">
<div id="article-text">
<div class="article-info">
<div id="article-time" style="margin-bottom: 20px;">
<p>{{ post.date | date: "%d %B %Y" }}</p>
</div>
<div id="article-title">
<a href="{{ post.url }}">
{{ post.title }}
</a>
</div>
</div>
</div>
</div>
{% endfor %}
And,
{% for post in paginator.posts %}
{% assign year = post.date | date: "%Y" %}
{% if year == '2021' %}
<div class="article-template" style="min-height: 100px;">
<div id="article-text">
<div class="article-info">
<div id="article-time" style="margin-bottom: 20px;">
<p>{{ post.date | date: "%d %B %Y" }}</p>
</div>
<div id="article-title">
<a href="{{ post.url }}">
{{ post.title }}
</a>
</div>
</div>
</div>
</div>
{% endif %}
{% endfor %}
It looks a lot harder than I originally thought. What am I missing here?