in src/wordpress.js [71:102]
async function fetchAll({ numPages, endPoint, type }) {
const allPages = [];
let allData = [];
// eslint-disable-next-line no-console
console.debug(`Fetching ${type} content from wordpress via REST API`);
for (let pageNum = 1; pageNum <= numPages; pageNum++) {
// console.log(`${endPoint}&page=${pageNum}`);
const page = fetch(`${endPoint}&page=${pageNum}`);
allPages.push(page);
}
const results = await Promise.all(allPages);
for (const result of results) {
let json = await result.json();
// Filter post data and only keep/cache what we care about.
if (type === 'posts') {
json = json
.filter((item) => {
return item.status === 'publish' && item.slug;
})
.map(createPost);
}
allData.push(json);
allData = allData.flat();
}
return allData;
}