forked from HZooly/built-with-gridsome
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgridsome.server.js
33 lines (29 loc) · 937 Bytes
/
gridsome.server.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
const cw = require("capture-website");
const crypto = require("crypto");
const projects = require("./projects.json");
module.exports = function(api) {
api.loadSource(async actions => {
const contentTypeProjects = actions.addCollection("Project");
for (const [index, project] of projects.entries()) {
const randomId = crypto.randomBytes(12).toString("hex");
try {
await cw.file(project.url, `./src/assets/img/${randomId}.png`, {
scaleFactor: 1,
timeout: 360
});
project.image = `${randomId}.png`;
} catch (err) {
console.log(`Capture website error: project ${project.name}`, err);
}
contentTypeProjects.addNode({
id: index,
name: project.name,
image: project.image,
description: project.description,
url: project.url,
source: project.source,
tags: project.tags
});
}
});
};