forked from stackbit/jamstackthemes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcapture-screenshots.js
60 lines (50 loc) · 1.58 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env node
const Pageres = require('pageres');
const fs = require('fs');
const path = require('path');
const yamlFront = require('yaml-front-matter');
const gh = require('parse-github-url');
const themesFolder = './content/theme';
const themeFiles = fs.readdirSync(themesFolder);
const hiresImagesFolder = './static/capture';
console.log("******************")
console.log("Taking Screenshots")
console.log("******************")
captureWebScreenshot = async theme => {
const data = fs.readFileSync(path.join(themesFolder, theme));
const frontmatter = yamlFront.loadFront(data);
let github = gh(frontmatter.github);
let branch = frontmatter.github_branch ? frontmatter.github_branch : 'master';
if (frontmatter.disabled) {
return false
}
if (github) {
let themeKey = github.repo.replace("/", "-").toLowerCase() + "-" + branch;
let themeImage = `${themeKey}.png`
const url = frontmatter.demo
if (fs.existsSync(path.join(hiresImagesFolder, themeImage))) {
console.log(`${theme} skipped`)
return false
} else {
console.log(`${theme} capturing`);
const page = await new Pageres({delay: 2, filename: themeKey})
.src(url, ['1024x768'], {crop: true})
.dest(hiresImagesFolder)
.run();
return page
}
}
return false;
};
// Promise.all(themeFiles.map(theme => {
// captureWebScreenshot(theme)
// })).then(res => {
// }).catch(error => {
// console.log(error.message);
// });
const captureAll = async () => {
for(const theme of themeFiles) {
await captureWebScreenshot(theme)
}
}
captureAll()