-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
capture-screenshots.js
39 lines (33 loc) · 857 Bytes
/
capture-screenshots.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const captureWebsite = require('capture-website')
const pLimit = require('p-limit')
const limit = pLimit(1)
const sites = require('./sites.json')
const options = {
width: 1920,
height: 1000,
overwrite: true
}
const urls = sites
.filter(site => site.id)
.reduce((acc, site) => {
return acc.concat([
[site.url, site.id],
[site.secondaryUrl, `${site.id}-2`]
])
}, [])
const captures = urls.map(([url, filename]) => {
return limit(async () => {
try {
console.log(`Capturing ${url}`)
await captureWebsite.file(url, `images/${filename}.png`, options)
console.log(` ${url} written to ${filename}`)
} catch (e) {
console.log(`Failed capturing ${url}`)
}
})
})
;(async () => {
console.log('Beginning screenshots')
await Promise.all(captures)
console.log('Finished screenshots')
})