-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
gatsby-node.js
59 lines (51 loc) · 1.4 KB
/
gatsby-node.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
/* eslint-disable @typescript-eslint/no-var-requires */
const fs = require('fs');
const path = require('path');
const puppeteer = require('puppeteer');
// eslint-disable-next-line no-undef
module.exports = {
onCreateBabelConfig: ({ actions }) => {
actions.setBabelPreset({
name: 'babel-preset-gatsby',
options: {
reactRuntime: 'automatic',
},
});
},
onPreBuild: async () => {
const browserFetcher = puppeteer.createBrowserFetcher();
const revisionInfo = await browserFetcher.download('982053');
const browser = await puppeteer.launch({
executablePath:
revisionInfo.executablePath || process.env.PUPPETEER_EXECUTABLE_PATH,
headless: true,
});
const page = await browser.newPage();
// 병렬로 할 수 없음
await screenshot(page, {
url: 'https://www.radix-ui.com/',
filename: 'radix-ui',
});
await screenshot(page, {
url: 'https://so-so.dev/',
filename: 'soso',
});
await screenshot(page, {
url: 'https://apple.com',
filename: 'apple',
});
await browser.close();
},
};
async function screenshot(page, { url, filename }) {
await page.goto(url);
const screenshotBuffer = await page.screenshot();
const screenshotPath = path.join(
__dirname,
'src',
'images',
'link-preview',
`${filename}.png`
);
fs.writeFileSync(screenshotPath, screenshotBuffer);
}