/
3-add-styled-block.js
70 lines (62 loc) · 1.99 KB
/
3-add-styled-block.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
61
62
63
64
65
66
67
68
69
70
import { Client } from "@notionhq/client"
import { config } from "dotenv"
config()
const pageId = process.env.NOTION_PAGE_ID
const apiKey = process.env.NOTION_API_KEY
const notion = new Client({ auth: apiKey })
/*
---------------------------------------------------------------------------
*/
/**
* Resources:
* - Appending block children endpoint (notion.blocks.children.append(): https://developers.notion.com/reference/patch-block-children)
* - Rich text options: https://developers.notion.com/reference/rich-text
* - Working with page content guide: https://developers.notion.com/docs/working-with-page-content
*/
async function main() {
const blockId = pageId // Blocks can be appended to other blocks *or* pages. Therefore, a page ID can be used for the block_id parameter
const styledLinkTextResponse = await notion.blocks.children.append({
block_id: blockId,
children: [
{
heading_3: {
rich_text: [
{
text: {
content: "Tuscan kale",
},
},
],
},
},
{
paragraph: {
rich_text: [
{
text: {
// Paragraph text
content:
"Tuscan kale is a variety of kale with a long tradition in Italian cuisine, especially that of Tuscany. It is also known as Tuscan kale, Italian kale, dinosaur kale, kale, flat back kale, palm tree kale, or black Tuscan palm.",
link: {
// Paragraph link
url: "https://en.wikipedia.org/wiki/Kale",
},
},
annotations: {
// Paragraph styles
bold: true,
italic: true,
strikethrough: true,
underline: true,
color: "green",
},
},
],
},
},
],
})
// Print the new block(s) response
console.log(styledLinkTextResponse)
}
main()