Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

📝 Blog #31

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Finish pagination
  • Loading branch information
MWDelaney committed Sep 16, 2022
commit d6e03f574931432fb2c38cb7bd5dbe40dc97d8ee
20 changes: 19 additions & 1 deletion src/assets/views/partials/pagination.njk
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<nav class="pagination">
<ul>
{% if tag %}

{% if tag.pageNumber != 0 %}
{% set showPrevious = true %}
{% else %}
@@ -72,9 +73,26 @@
{% else %}
{% set highlighted = false %}
{% endif %}

{% if tag %}
{% if loop.index <= 1 %}
{% set url = '/blog/' + tag.slug + '/' %}
{% else %}
{% set url = '/blog/' + tag.slug + '/page/' + loop.index + '/' %}
{% endif %}
{% else %}
{% set url = pagination.hrefs[ loop.index0 ] %}
{% endif %}

{% set show = false %}

{% if loop.index0 <= totalPages %}
{% set show = true %}
{% endif %}

{% if show %}
{# finally print some HTML #}
<li class="{% if currentPage %}current-page{% endif %} {% if highlighted == true %}highlighted{% endif %}"><a href="{{ pagination.hrefs[ loop.index0 ] }}"{% if page.url == pagination.hrefs[ loop.index0 ] %} aria-current="page"{% endif %}><span class="sr-only">Page </span>{{ loop.index }}</a></li>
<li class="{% if currentPage %}current-page{% endif %} {% if highlighted == true %}highlighted{% endif %}"><a href="{{ url }}"{% if page.url == url %} aria-current="page"{% endif %}><span class="sr-only">Page </span>{{ loop.index }}</a></li>
{% endif %}
{% endfor %}
</ol>
2 changes: 1 addition & 1 deletion src/config/collections.js
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ module.exports = {
let pagedItems = _.chunk(tagItems, paginationSize);
for( let pageNumber = 0, max = pagedItems.length; pageNumber < max; pageNumber++) {
tagMap.push({
tagName: tagName,
slug: tagName,
totalPages: (max - 1),
pageNumber: pageNumber,
posts: pagedItems[pageNumber]
1 change: 1 addition & 0 deletions src/config/filters.js
Original file line number Diff line number Diff line change
@@ -4,4 +4,5 @@
*/

module.exports = {

}
6 changes: 3 additions & 3 deletions src/content/blog-tags.njk
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
layout: base.njk
permalink: /blog/{{ tag.tagName | slugify }}/{% if tag.pageNumber > 0 %}/page/{{ tag.pageNumber + 1 }}{% endif %}/index.html
permalink: /blog/{{ tag.slug | slugify }}/{% if tag.pageNumber > 0 %}/page/{{ tag.pageNumber + 1 }}{% endif %}/index.html
pagination:
data: collections.postsByTag
size: 1
alias: tag
addAllPagesToCollections: true
eleventyComputed:
title: Blog entries with tag &quot;{{ tag.tagName }}&quot; {% if tag.pageNumber > 0 %}, (Page {{ tag.pageNumber + 1 }}) {% endif %}
title: Blog entries with tag &quot;{{ tag.slug }}&quot; {% if tag.pageNumber > 0 %}, (Page {{ tag.pageNumber + 1 }}) {% endif %}
---
<section class="blog blog-tag blog-tag-{{ tag.tagName }}">
<section class="blog blog-tag blog-tag-{{ tag.slug }}">
{% for post in tag.posts %}
{% include "partials/blog-item.njk" %}
{% endfor %}