forked from NotionX/react-notion-x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
[pageId].tsx
71 lines (61 loc) · 1.66 KB
/
[pageId].tsx
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
71
import * as React from 'react'
import { ExtendedRecordMap } from 'notion-types'
import { getAllPagesInSpace } from 'notion-utils'
import { defaultMapPageUrl } from 'react-notion-x'
import * as notion from '../lib/notion'
import { NotionPage } from '../components/NotionPage'
import {
isDev,
previewImagesEnabled,
rootDomain,
rootNotionPageId,
rootNotionSpaceId
} from '../lib/config'
export const getStaticProps = async (context) => {
const pageId = context.params.pageId as string
const recordMap = await notion.getPage(pageId)
return {
props: {
recordMap
},
revalidate: 10
}
}
export async function getStaticPaths() {
if (isDev) {
return {
paths: [],
fallback: true
}
}
const mapPageUrl = defaultMapPageUrl(rootNotionPageId)
// This crawls all public pages starting from the given root page in order
// for next.js to pre-generate all pages via static site generation (SSG).
// This is a useful optimization but not necessary; you could just as easily
// set paths to an empty array to not pre-generate any pages at build time.
const pages = await getAllPagesInSpace(
rootNotionPageId,
rootNotionSpaceId,
notion.getPage,
{
traverseCollections: false
}
)
const paths = Object.keys(pages)
.map((pageId) => mapPageUrl(pageId))
.filter((path) => path && path !== '/')
return {
paths,
fallback: true
}
}
export default function Page({ recordMap }: { recordMap: ExtendedRecordMap }) {
return (
<NotionPage
recordMap={recordMap}
rootDomain={rootDomain}
rootPageId={rootNotionPageId}
previewImagesEnabled={previewImagesEnabled}
/>
)
}