-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-notion-pages.js
46 lines (35 loc) · 1.41 KB
/
update-notion-pages.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
const fs = require('fs');
const path = require('path');
const { NotionAPI } = require('notion-client');
const axios = require('axios');
const PAGES = {
fa8f3e0647af4384862471b606d6a35a: path.join(__dirname, 'src', 'contants', 'ventures.json'),
ef891e94750245adaed2f72f262168b0: path.join(__dirname, 'src', 'contants', 'vagas.json'),
};
const notion = new NotionAPI();
const main = async () => {
const imagesDir = path.join(__dirname, 'static', 'assets', 'notion');
if (fs.existsSync(imagesDir)) {
fs.rmdirSync(imagesDir, { recursive: true });
}
fs.mkdirSync(imagesDir);
await Promise.all(Object.entries(PAGES).map(async ([pageId, jsonPath]) => {
const recordMap = await notion.getPage(pageId);
await Promise.all(Object.entries(recordMap.signed_urls).map(async ([urlID, signedURL]) => {
const response = await axios.request({
responseType: 'arraybuffer',
url: signedURL,
});
const url = signedURL.split('?')[0];
const { name, ext } = path.parse(url);
const filename = `${name}${ext}`;
const filepath = path.join(imagesDir, filename);
fs.writeFileSync(filepath, response.data);
recordMap.signed_urls[urlID] = `https://kassellabs.io/assets/notion/${filename}`;
}));
const recordMapString = JSON.stringify(recordMap, null, 2);
fs.writeFileSync(jsonPath, recordMapString);
}));
console.log('Notion Pages JSONs Updated');
};
main();