-
Notifications
You must be signed in to change notification settings - Fork 2
/
makeThumbnails.js
80 lines (68 loc) · 2.02 KB
/
makeThumbnails.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const { exec } = require('child_process');
const puppeteer = require('puppeteer');
const visualizationsList = require('./src/visualizationsList.json');
let signal = null;
const langs = ['fr', 'en'];
const Screenshot = async () => {
console.log('starting screenshotting')
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.setViewport({
width: 1200,
height: 800,
deviceScaleFactor: 1,
});
await page.waitForTimeout(1000);
for (const i in langs) {
const lang = langs[i];
const PATH_BASE = `./public/thumbnails/${lang}`;
for (const j in visualizationsList) {
const vis = visualizationsList[j];
const url = `http://localhost:3000/${lang}/visualization/${vis.id}`;
const path = `${PATH_BASE}/${vis.id}.png`;
console.log(+j + 1, '/', visualizationsList.length);
console.log('snapshoting ', url);
console.log('saving it to', path);
await page.goto(url, {
waitUntil: 'networkidle2',
});
if (i === 0 && j === 0) {
await page.waitForTimeout(4000);
}
await page.waitForTimeout(4000);
await page.screenshot({
path,
fullPage: true
});
// await page.waitForTimeout(1500);
// // doing it twice
// await page.screenshot({
// path,
// fullPage: true
// });
// await page.waitForTimeout(1000);
}
}
await page.close();
await browser.close();
console.log('done')
}
// signal = exec('yarn start', (error, stdout, stderr) => {
// if (error) {
// console.error(`error: ${error.message}`);
// return;
// }
// if (stderr) {
// console.error(`stderr: ${stderr}`);
// return;
// }
// console.log(`stdout:\n${stdout}`);
// const port = stdout.match(/Something is already running on port (\d+)/);
// console.log('port', port);
// console.log('screenshotting');
// });
Screenshot()
// .then(() => {
// console.log('will kill');
// process.kill(-signal.pid);
// })