Reputation: 382
i am using Pageres to generate a screenshot from multiple websites.
With one source, all works fine!
Example code:
return new Pageres({})
.src(url, sizes) // <- one URL
.dest(dest)
.run()
.then((result) => {
console.log("done");
return result;
})
.catch((error) => {
throw error;
});
But if i wanted to use more then one source and iterate through my array, it returns a Pageres Object instead of a Promise.
My Code looks like:
let pages = new Pageres({});
urls.forEach((url)=>{
pages.src(url, size)
});
pages
.dest(dest)
.run()
.then((result) => {
console.log("done");
return result
})
.catch((error) => {
console.log("error", error);
throw error;
});
return pages;
Does someone know why the first example works and the second does not? What can i do to return a Promise in the second example?
Thanks in advance!
Upvotes: 2
Views: 94
Reputation: 39290
I think you can use reduce
let pages = urls.reduce(
(page,url)=>
page.src(url,size),
,new Pageres({})
);
return pages
.dest(dest)
.run()
.then((result) => {
console.log("done");
return result
})
.catch((error) => {
console.log("error", error);
throw error;
});
Upvotes: 2