Skip to content

Commit d41f8fb

Browse files
committed
2 parents ffccd3a + 05fc72a commit d41f8fb

File tree

5 files changed

+887
-506
lines changed

5 files changed

+887
-506
lines changed

Diff for: README.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
![npm version](https://badgen.net/npm/v/react-notion) ![npm version](https://badgen.net/david/dep/splitbee/react-notion) ![minzipped sized](https://badgen.net/bundlephobia/minzip/react-notion)
44

5+
56
A React renderer for Notion pages.
67
Use Notion as CMS for your blog, documentation or personal site.
78

89
_This packages doesn't handle the communication with the API. Check out [notion-api-worker](https://github.com/splitbee/notion-api-worker) for an easy solution_.
910

11+
<sub>Created by <a href="https://twitter.com/timolins">Timo Lins</a> & <a href="https://twitter.com/linstobias">Tobias Lins</a> with the help of all <a href="https://github.com/splitbee/react-notion/graphs/contributors">contributors</a> ❤️</sub>
12+
1013
## Features
1114

1215
⚡️ **Fast** – Up to 10x faster than Notion\*
@@ -118,3 +121,4 @@ Most common block types are supported. We happily accept pull requests to add su
118121
- [Tobias Lins](https://tobi.sh) – Idea, Code
119122
- [Timo Lins](https://timo.sh) – Code, Documentation
120123
- [samwightt](https://github.com/samwightt) – Inspiration & API Typings
124+
- [All people that contributed 💕](https://github.com/splitbee/react-notion/graphs/contributors)

Diff for: example/pages/[pageId].tsx

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { NotionRenderer, BlockMapType } from "react-notion";
2+
import Head from "next/head";
3+
import fetch from "node-fetch";
4+
5+
export async function getServerSideProps(context) {
6+
const pageId = context.params?.pageId.split("-").reverse()[0];
7+
8+
if (!pageId) {
9+
return;
10+
}
11+
12+
const data: BlockMapType = await fetch(
13+
`https://notion-api.splitbee.io/v1/page/${pageId}`
14+
).then(res => res.json());
15+
16+
return {
17+
props: {
18+
blockMap: data
19+
}
20+
};
21+
}
22+
23+
const NotionPage = ({ blockMap }) => {
24+
if (!blockMap || Object.keys(blockMap).length === 0) {
25+
return (
26+
<div>
27+
<h3>No data found.</h3>
28+
<div> Make sure the pageId is valid.</div>
29+
<div>Only public pages are supported in this example.</div>
30+
</div>
31+
);
32+
}
33+
34+
const title =
35+
blockMap[Object.keys(blockMap)[0]]?.value.properties.title[0][0];
36+
37+
return (
38+
<div
39+
style={{
40+
maxWidth: 708,
41+
margin: "0 auto",
42+
padding: "0 8px",
43+
fontFamily: `-apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, "Apple Color Emoji", Arial, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol"`
44+
}}
45+
>
46+
<Head>
47+
<title>{title}</title>
48+
</Head>
49+
<NotionRenderer blockMap={blockMap} />
50+
<style jsx>{`
51+
div :global(.notion-code) {
52+
box-sizing: border-box;
53+
}
54+
`}</style>
55+
</div>
56+
);
57+
};
58+
59+
export default NotionPage;

Diff for: example/pages/index.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ const Home = ({ blockMap }) => (
2323
fontFamily: `-apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, "Apple Color Emoji", Arial, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol"`
2424
}}
2525
>
26+
<Head>
27+
<title>react-notion example</title>
28+
</Head>
2629
<NotionRenderer blockMap={blockMap} />
2730
</div>
2831
);

0 commit comments

Comments
 (0)