forked from transitive-bullshit/nextjs-notion-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path[pageId].tsx
59 lines (49 loc) · 1.31 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
import React from 'react'
import { isDev, domain } from 'lib/config'
import { getSiteMaps } from 'lib/get-site-maps'
import { resolveNotionPage } from 'lib/resolve-notion-page'
import { NotionPage } from 'components'
export const getStaticProps = async (context) => {
const rawPageId = context.params.pageId as string
try {
if (rawPageId === 'sitemap.xml' || rawPageId === 'robots.txt') {
return {
redirect: {
destination: `/api/${rawPageId}`
}
}
}
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 siteMaps = await getSiteMaps()
const ret = {
paths: siteMaps.flatMap((siteMap) =>
Object.keys(siteMap.canonicalPageMap).map((pageId) => ({
params: {
pageId
}
}))
),
// paths: [],
fallback: true
}
console.log(ret.paths)
return ret
}
export default function NotionDomainDynamicPage(props) {
return <NotionPage {...props} />
}