You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A renderer for Notion pages. It is written in TypeScript. Use Notion as CMS for your blog, documentation or personal site, while we wait for the official API.
This packages does not include an API wrapper. You can find some interesting projects here: [notionapi-agent](https://github.com/dragonman225/notionapi-agent)
5
+
A React renderer for Notion pages.
6
+
Use Notion as CMS for your blog, documentation or personal site.
7
+
8
+
_This packages doesn't handle the communication with the API._
9
+
10
+
## Features
11
+
12
+
⚡️ **Fast** – Up to 10x faster than Notion\*
13
+
🎯 **Precise** – Results are _almost_ identical
14
+
🔮 **Code Highlighting** – Automatic code highlighting with [prismjs](https://prismjs.com/)
15
+
🎨 **Custom Styles** – Styles are easily adaptable. Optional styles included
16
+
17
+
_\* First Meaningful Paint compared to an example hosted on [ZEIT now](https://zeit.co/now)._
6
18
7
19
## Install
8
20
@@ -12,14 +24,17 @@ npm install react-notion
12
24
13
25
## How to use
14
26
27
+
#### Minimal Example
28
+
29
+
We can store the API response in a `.json` file and import it.
30
+
15
31
```js
16
-
import { NotionRenderer } from"react-notion";
17
32
import"react-notion/src/styles.css";
18
-
19
33
import"prismjs/themes/prism-tomorrow.css"; // only needed if you use Code Blocks
A working example, built with Next.js, can be found inside the `example` directory.
47
+
A working example can be found inside the `example` directory.
33
48
34
-
##Currently supported block types:
49
+
#### Next.js Example
35
50
36
-
-[x] Text
37
-
-[x] Headings
38
-
-[x] Images
39
-
-[x] Quotes
40
-
-[x] Bulleted Lists
41
-
-[x] Numbered Lists
42
-
-[x] Links
43
-
-[x] Columns
44
-
-[x] iFrames
45
-
-[x] Videos
46
-
-[x] Divider
47
-
-[x] Callout
48
-
-[x] Image Captions
49
-
-[x] Code Blocks
51
+
In this example we use [Next.js](https://github.com/zeit/next.js) for SSG. We use [notionapi-agent](https://github.com/dragonman225/notionapi-agent) to fetch data from the API.
50
52
51
-
Missing
53
+
To get your `pageId`, inspect network requests while visiting a public Notion page. It is included in the body of the `POST /api/v3/loadPageChunk` request.
52
54
53
-
-[ ] Checkboxes
54
-
-[ ] Toggle Lists
55
-
-[ ] Tables
55
+
`/pages/my-post.jsx`
56
+
57
+
```js
58
+
import"react-notion/src/styles.css";
59
+
import"prismjs/themes/prism-tomorrow.css";
60
+
import { NotionRenderer } from"react-notion";
61
+
import { createAgent } from"notionapi-agent";
62
+
63
+
constagent=createAgent();
64
+
65
+
exportasyncfunctiongetStaticProps() {
66
+
constpageId="2e22de6b-770e-4166-be30-1490f6ffd420"; // Your Notion Page ID
67
+
constpageChunk=awaitagent.loadPageChunk({
68
+
pageId,
69
+
limit:999,
70
+
chunkNumber:0,
71
+
cursor: { stack: [] },
72
+
verticalColumns:false
73
+
});
74
+
75
+
return {
76
+
props: {
77
+
blockMap:pageChunk.recordMap.block
78
+
}
79
+
};
80
+
}
81
+
82
+
exportdefault ({ blockMap }) => (
83
+
<div style={{ maxWidth:768 }}>
84
+
<NotionRenderer blockMap={blockMap} />
85
+
</div>
86
+
);
87
+
```
56
88
57
89
## Sites using react-notion
58
90
91
+
List of pages that implement this library.
92
+
59
93
-[PS Tunnel](https://pstunnel.com/blog)
60
94
-[Splitbee](https://splitbee.io/blog)
61
95
96
+
## Supported Blocks
97
+
98
+
Most common block types are supported. We happily accept new pull requests to add support for the missing blocks.
0 commit comments