forked from 11ty/11ty-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node-screenshots.js
36 lines (33 loc) · 954 Bytes
/
node-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
const puppeteer = require("puppeteer");
const slugify = require("slugify");
const sharp = require("sharp");
const fastestSites = require("./_data/fastestSites.json");
async function screenshot(url, fileSlug) {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(url);
await page.setViewport({
width: 1024,
height: 768,
deviceScaleFactor: 1,
});
let fullFilename = `./img/sites/${fileSlug}_full.jpg`;
let filename = `./img/sites/${fileSlug}.jpg`;
await page.screenshot({
path: fullFilename,
type: "jpeg",
quality: 80
});
await sharp(fullFilename).resize(405).toFile(filename);
await browser.close();
}
(async () => {
for(let site of fastestSites) {
if(site.rank <= 11) {
console.log( "Fetching", site.url );
let slug = site.url.replace(/https?\:\//, "");
let filename = slugify(slug, { lower: true, remove: /[:\/]/g });
await screenshot(site.url, filename);
}
}
})();