Skip to content

Commit 47d4a35

Browse files
fix: resolve issue with pagination URLs (#8)
1 parent 6aec75b commit 47d4a35

18 files changed

+102
-29
lines changed

.github/pull_request_template.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
2. <!-- Second step -->
1616
3. <!-- and so on... -->
1717

18-
**Expected behavioor:** <!-- What should happen -->
18+
**Expected behaviour:** <!-- What should happen -->
1919

2020
## Additional information
2121

package-lock.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"@11ty/eleventy-navigation": "0.3.5",
3434
"@11ty/eleventy-plugin-rss": "1.2.0",
3535
"@11ty/eleventy-plugin-syntaxhighlight": "5.0.0",
36-
"eleventy-plugin-fluid": "2.3.1",
36+
"eleventy-plugin-fluid": "2.3.2",
3737
"infusion": "4.6.0",
3838
"netlify-cms": "2.10.192",
3939
"prop-types": "15.8.1",

src/_includes/layouts/posts.njk

+16-11
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,22 @@
99
{% endblock %}
1010

1111
{% block content %}
12-
{% if posts.length %}
13-
{% for item in posts %}
14-
<article class="entry">
15-
<h2><a href="{{ item.url }}">{{ item.data.title }}</a></h2>
16-
<p class="metadata"><time datetime="{{ item.data.date | isoDate }}" class="dt-published">{{ item.data.date | formatDate }}</time></p>
17-
{% if item.data.excerpt %}
18-
<p>{{ item.data.excerpt | safe }}</p>
19-
{% endif %}
20-
</article>
21-
{% endfor %}
22-
{% endif %}
12+
13+
{# In circumstances where pagination size is set to 1, the paginated content will be a single item instead of an array.
14+
The following code ensures we are always handling an array, even if it only has one item. #}
15+
16+
{% set items = [] %}
17+
{% set items = items.concat(posts) %}
18+
19+
{% for item in items %}
20+
<article class="entry">
21+
<h2><a href="{{ item.url }}">{{ item.data.title }}</a></h2>
22+
<p class="metadata"><time datetime="{{ item.data.date | isoDate }}" class="dt-published">{{ item.data.date | formatDate }}</time></p>
23+
{% if item.data.excerpt %}
24+
<p>{{ item.data.excerpt | safe }}</p>
25+
{% endif %}
26+
</article>
27+
{% endfor %}
2328

2429
{% if pagination.href.previous or pagination.href.next %}
2530
{% include "partials/components/pagination.njk" %}
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<nav class="pagination" aria-label="posts pagination">
22
<ul>
33
{%- if pagination.href.previous %}
4-
<li><a href="{{ pagination.href.previous }}">&larr;<span class="visually-hidden">previous</span></a></li>
4+
<li><a href="{{ pagination.href.previous }}"><span aria-hidden="true">&larr;</span><span class="visually-hidden">previous</span></a></li>
55
{%- endif %}
66
{%- for pageEntry in pagination.pages %}
7-
<li><a href="{{ pagination.hrefs[ loop.index0 ] }}"{% if page.url == pagination.hrefs[ loop.index0 ] %} aria-current="page"{% endif %}>{{ loop.index }}</a></li>
7+
<li><a href="{{ pagination.hrefs[ loop.index0 ] }}"{% if page.url == pagination.hrefs[ loop.index0 ] %} aria-current="page"{% endif %} aria-label="Page {{ loop.index }} of {{ pagination.pages.length }}">{{ loop.index }}</a></li>
88
{%- endfor %}
99
{%- if pagination.href.next %}
10-
<li><a href="{{ pagination.href.next }}"><span class="visually-hidden">next</span>&rarr;</a></li>
10+
<li><a href="{{ pagination.href.next }}"><span class="visually-hidden">next</span><span aria-hidden="true">&rarr;</span></a></li>
1111
{%- endif %}
1212
</ul>
1313
</nav>

src/collections/pages/pages.11tydata.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
const { generatePermalink } = require("eleventy-plugin-fluid");
44

55
module.exports = {
6+
permalink: data => generatePermalink(data, "pages"),
67
eleventyComputed: {
78
eleventyNavigation: data => {
89
/* If this page has an `order` attribute, create an Eleventy Navigation object for it. */
@@ -15,7 +16,6 @@ module.exports = {
1516
};
1617
}
1718
return false;
18-
},
19-
permalink: data => generatePermalink(data, "pages")
19+
}
2020
}
2121
};

src/collections/posts/my-post.md src/collections/posts/post-1.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: My Post
2+
title: Post 1
33
date: 2020-06-22
44
excerpt: This is a short description of the post.
55
author: Fluid Project

src/collections/posts/post-10.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: Post 10
3+
date: 2020-07-01
4+
excerpt: This is a short description of the post.
5+
author: Fluid Project
6+
---
7+
You can write content for your post in [Markdown](https://www.11ty.dev/docs/languages/markdown/) format.

src/collections/posts/post-11.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: Post 11
3+
date: 2020-07-02
4+
excerpt: This is a short description of the post.
5+
author: Fluid Project
6+
---
7+
You can write content for your post in [Markdown](https://www.11ty.dev/docs/languages/markdown/) format.

src/collections/posts/post-2.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: Post 2
3+
date: 2020-06-23
4+
excerpt: This is a short description of the post.
5+
author: Fluid Project
6+
---
7+
You can write content for your post in [Markdown](https://www.11ty.dev/docs/languages/markdown/) format.

src/collections/posts/post-3.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: Post 3
3+
date: 2020-06-24
4+
excerpt: This is a short description of the post.
5+
author: Fluid Project
6+
---
7+
You can write content for your post in [Markdown](https://www.11ty.dev/docs/languages/markdown/) format.

src/collections/posts/post-4.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: Post 4
3+
date: 2020-06-25
4+
excerpt: This is a short description of the post.
5+
author: Fluid Project
6+
---
7+
You can write content for your post in [Markdown](https://www.11ty.dev/docs/languages/markdown/) format.

src/collections/posts/post-5.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: Post 5
3+
date: 2020-06-26
4+
excerpt: This is a short description of the post.
5+
author: Fluid Project
6+
---
7+
You can write content for your post in [Markdown](https://www.11ty.dev/docs/languages/markdown/) format.

src/collections/posts/post-6.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: Post 6
3+
date: 2020-06-27
4+
excerpt: This is a short description of the post.
5+
author: Fluid Project
6+
---
7+
You can write content for your post in [Markdown](https://www.11ty.dev/docs/languages/markdown/) format.

src/collections/posts/post-7.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: Post 7
3+
date: 2020-06-28
4+
excerpt: This is a short description of the post.
5+
author: Fluid Project
6+
---
7+
You can write content for your post in [Markdown](https://www.11ty.dev/docs/languages/markdown/) format.

src/collections/posts/post-8.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: Post 8
3+
date: 2020-06-29
4+
excerpt: This is a short description of the post.
5+
author: Fluid Project
6+
---
7+
You can write content for your post in [Markdown](https://www.11ty.dev/docs/languages/markdown/) format.

src/collections/posts/post-9.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
title: Post 9
3+
date: 2020-06-30
4+
excerpt: This is a short description of the post.
5+
author: Fluid Project
6+
---
7+
You can write content for your post in [Markdown](https://www.11ty.dev/docs/languages/markdown/) format.

src/collections/posts/posts.11tydata.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@ const { generatePermalink } = require("eleventy-plugin-fluid");
44

55
module.exports = {
66
layout: "layouts/post",
7-
eleventyComputed: {
8-
permalink: data => generatePermalink(data, "posts")
9-
}
7+
permalink: data => generatePermalink(data, "posts")
108
};

0 commit comments

Comments
 (0)