From 88b914cd8d702271681956e52ebeb2bdfbdce0ee Mon Sep 17 00:00:00 2001 From: Robin Abrahamsson Date: Mon, 8 Feb 2021 22:55:52 +0100 Subject: [PATCH] feat(pagination): added pagination urls to sitemap --- src/sitemapItems.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/sitemapItems.js b/src/sitemapItems.js index 0dc9497..f0b074b 100644 --- a/src/sitemapItems.js +++ b/src/sitemapItems.js @@ -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));