Skip to content

Commit

Permalink
feat(pagination): added pagination urls to sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
rq-abrahamsson committed Apr 2, 2021
1 parent da7a4a1 commit 88b914c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/sitemapItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,28 @@
const sitemapItem = require("./sitemapItem");
const sitemapProperty = require("./sitemapProperty");

function isPagination(item) {
return (
item !== undefined &&
item.data !== undefined &&
item.data.pagination !== undefined &&
item.data.pagination.pages !== undefined
);
}

function getPaginationUrls(item) {
if (isPagination(item)) {
return item.data.pagination.pages.map((page) => ({
...item,
url: page.url,
}));
}

return [item];
}

module.exports = (items, options) =>
items
.filter((item) => !sitemapProperty(item, "ignore") && item.url)
.flatMap(getPaginationUrls)
.map((item) => sitemapItem(item, options));

0 comments on commit 88b914c

Please sign in to comment.