-
Notifications
You must be signed in to change notification settings - Fork 0
/
screen.js
42 lines (38 loc) · 1.17 KB
/
screen.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
const projects = require('./content/projects.json');
const utils = require( './utils' );
const Pageres = require('pageres');
const fs = require('fs');
const sharp = require('sharp');
const options = {
delay: 2
};
projects.forEach((p) => {
let url = p.url;
const DIR = `${__dirname}/public/images/`;
const filename = utils.getImageSrcFromUri(url);
if (url.indexOf('/') === 0) {
url = `https://jdlrobson.com${url}`;
}
if (p.path) {
url += p.path;
}
console.log(`Building screenshot for ${url}`);
(async () => {
await new Pageres(options)
.src(url, [p.mobile ? '360x640' : '1920x1080' ],
{filename, crop: true, script: p.script}
)
.dest(DIR)
.run();
console.log(`Built screenshot for ${url}`);
sharp(fs.readFileSync(`${DIR}/${filename}.png`))
.resize(320)
.toFile(`${DIR}/${filename}.png`, (err, info) => {
if (err) {
console.log('Error resizing');
} else {
console.log(`Resized ${filename}`)
}
});
})();
})