forked from transitive-bullshit/nextjs-notion-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path[pageId].tsx
54 lines (44 loc) · 1.26 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
import * as React from 'react'
import { GetStaticProps } from 'next'
import { NotionPage } from '@/components/NotionPage'
import { domain, isDev } from '@/lib/config'
import { getSiteMap } from '@/lib/get-site-map'
import { resolveNotionPage } from '@/lib/resolve-notion-page'
import { PageProps, Params } from '@/lib/types'
export const getStaticProps: GetStaticProps<PageProps, Params> = async (
context
) => {
const rawPageId = context.params.pageId as string
try {
const props = await resolveNotionPage(domain, rawPageId)
return { props, revalidate: 10 }
} catch (err) {
console.error('page error', domain, rawPageId, err)
// we don't want to publish the error version of this page, so
// let next.js know explicitly that incremental SSG failed
throw err
}
}
export async function getStaticPaths() {
if (isDev) {
return {
paths: [],
fallback: true
}
}
const siteMap = await getSiteMap()
const staticPaths = {
paths: Object.keys(siteMap.canonicalPageMap).map((pageId) => ({
params: {
pageId
}
})),
// paths: [],
fallback: true
}
console.log(staticPaths.paths)
return staticPaths
}
export default function NotionDomainDynamicPage(props) {
return <NotionPage {...props} />
}