-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
51 lines (46 loc) · 1.16 KB
/
index.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
const { Client } = require('@notionhq/client')
const fs = require('fs')
const notion = new Client({ auth: process.env.NOTION_BEARER });
function toTitleCase (string) {
const parts = string.split('');
parts[0] = parts[0].toUpperCase();
return parts.join('');
}
(async () => {
const databaseID = process.env.PAINT_DATABASE_API;
const files = fs.readdirSync(__dirname + "/paints");
for (const json of files) {
const paints = require(__dirname + '/paints/' + json);
const tag = json.split('.')[0];
for (const [name, url] of Object.entries(paints)) {
const page = await notion.pages.create({
parent: {
database_id: databaseID
},
icon: {
type: "external",
external: {
url
}
},
properties: {
"Name": {
title: [
{
text: {
content: `${toTitleCase(tag)}: ${name}`
}
}
]
},
Type: {
select: {
name: tag
}
}
}
});
console.info(`created page ${page.id}`);
}
}
})();