Skip to content

Commit

Permalink
Adds support for serverlessFilter as a more straightforward way to …
Browse files Browse the repository at this point in the history
…fetch the chunk of paginated data in a serverless call
  • Loading branch information
zachleat committed Jan 8, 2022
1 parent 2d5be6c commit 7b8b43b
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/Plugins/Pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,19 @@ class Pagination {
// Warn: this doesn’t run filter/before/pagination transformations
// Warn: `pagination.pages`, pageNumber, links, hrefs, etc
let serverlessPaginationKey = this._get(data, data.pagination.serverless);
this.chunkedItems = [
[this._get(this.fullDataSet, serverlessPaginationKey)],
];

if (typeof data.pagination.serverlessFilter === "function") {
this.chunkedItems = [
data.pagination.serverlessFilter(
this.fullDataSet,
serverlessPaginationKey
),
];
} else {
this.chunkedItems = [
[this._get(this.fullDataSet, serverlessPaginationKey)],
];
}
} else {
// this returns an array
this.target = this._resolveItems();
Expand Down Expand Up @@ -311,7 +321,10 @@ class Pagination {

// TODO maybe also move this permalink additions up into the pagination class
let hasPermalinkField = Boolean(this.data[this.config.keys.permalink]);
let hasComputedPermalinkField = Boolean(this.data.eleventyComputed && this.data.eleventyComputed[this.config.keys.permalink]);
let hasComputedPermalinkField = Boolean(
this.data.eleventyComputed &&
this.data.eleventyComputed[this.config.keys.permalink]
);
if (pageNumber > 0 && !(hasPermalinkField || hasComputedPermalinkField)) {
cloned.setExtraOutputSubdirectory(pageNumber);
}
Expand Down

0 comments on commit 7b8b43b

Please sign in to comment.