Skip to content

Commit 25f60c3

Browse files
committed
Add support for custom pages in example
1 parent 422498e commit 25f60c3

File tree

3 files changed

+878
-504
lines changed

3 files changed

+878
-504
lines changed

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)