Skip to content

Commit

Permalink
Merge branch 'pagination-before-metadata' of https://github.com/vseve…
Browse files Browse the repository at this point in the history
…nter/eleventy into vseventer-pagination-before-metadata

# Conflicts:
#	src/Plugins/Pagination.js
#	test/PaginationTest.js
  • Loading branch information
zachleat committed Feb 18, 2022
2 parents 30e3551 + 42650ff commit aba3a57
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Plugins/Pagination.js
Expand Up @@ -172,7 +172,7 @@ class Pagination {
typeof this.data.pagination.before === "function"
) {
// we don’t need to make a copy of this because we .slice() above to create a new copy
result = this.data.pagination.before(result);
result = this.data.pagination.before(result, this.data);
}

if (this.data.pagination.reverse === true) {
Expand Down
12 changes: 12 additions & 0 deletions test/PaginationTest.js
Expand Up @@ -641,6 +641,18 @@ test("Pagination `before` Callback", async (t) => {
t.deepEqual(templates[0].data.myalias, "item6");
});

test("Pagination `before` Callback with metadata", async (t) => {
let tmpl = getNewTemplate(
"./test/stubs/paged/paged-before-metadata.njk",
"./test/stubs/",
"./dist"
);

let data = await tmpl.getData();
let templates = await tmpl.getTemplates(data);
t.deepEqual(templates[0].data.pagination.items, ["item3"]);
});

test("Pagination `before` Callback with a Filter", async (t) => {
let tmpl = getNewTemplate(
"./test/stubs/paged/paged-before-filter.njk",
Expand Down
14 changes: 14 additions & 0 deletions test/stubs/paged/paged-before-metadata.njk
@@ -0,0 +1,14 @@
---js
{
keyword: "item3",
pagination: {
data: "items",
size: 1,
before: function(data, metadata) {
return data.filter(el => el === metadata.keyword);
}
},
items: ["item1", "item2", "item3", "item4", "item5", "item6"]
}
---
<ol>{% for item in pagination.items %}<li>{{ item }}</li>{% endfor %}</ol>

0 comments on commit aba3a57

Please sign in to comment.