-
-
Notifications
You must be signed in to change notification settings - Fork 570
/
NotionPage.tsx
169 lines (154 loc) · 5.44 KB
/
NotionPage.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import dynamic from 'next/dynamic'
import Head from 'next/head'
// import Image from 'next/image'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { type ExtendedRecordMap } from 'notion-types'
import { getPageTitle } from 'notion-utils'
import { NotionRenderer } from 'react-notion-x'
import TweetEmbed from 'react-tweet-embed'
import { Loading } from './Loading'
// -----------------------------------------------------------------------------
// dynamic imports for optional components
// -----------------------------------------------------------------------------
const Code = dynamic(() =>
import('react-notion-x/build/third-party/code').then(async (m) => {
// additional prism syntaxes
await Promise.all([
import('prismjs/components/prism-markup-templating.js'),
import('prismjs/components/prism-markup.js'),
import('prismjs/components/prism-bash.js'),
import('prismjs/components/prism-c.js'),
import('prismjs/components/prism-cpp.js'),
import('prismjs/components/prism-csharp.js'),
import('prismjs/components/prism-docker.js'),
import('prismjs/components/prism-java.js'),
import('prismjs/components/prism-js-templates.js'),
import('prismjs/components/prism-coffeescript.js'),
import('prismjs/components/prism-diff.js'),
import('prismjs/components/prism-git.js'),
import('prismjs/components/prism-go.js'),
import('prismjs/components/prism-graphql.js'),
import('prismjs/components/prism-handlebars.js'),
import('prismjs/components/prism-less.js'),
import('prismjs/components/prism-makefile.js'),
import('prismjs/components/prism-markdown.js'),
import('prismjs/components/prism-objectivec.js'),
import('prismjs/components/prism-ocaml.js'),
import('prismjs/components/prism-python.js'),
import('prismjs/components/prism-reason.js'),
import('prismjs/components/prism-rust.js'),
import('prismjs/components/prism-sass.js'),
import('prismjs/components/prism-scss.js'),
import('prismjs/components/prism-solidity.js'),
import('prismjs/components/prism-sql.js'),
import('prismjs/components/prism-stylus.js'),
import('prismjs/components/prism-swift.js'),
import('prismjs/components/prism-wasm.js'),
import('prismjs/components/prism-yaml.js')
])
return m.Code
})
)
const Collection = dynamic(() =>
import('react-notion-x/build/third-party/collection').then(
(m) => m.Collection
)
)
const Equation = dynamic(() =>
import('react-notion-x/build/third-party/equation').then((m) => m.Equation)
)
const Pdf = dynamic(
() => import('react-notion-x/build/third-party/pdf').then((m) => m.Pdf),
{
ssr: false
}
)
const Modal = dynamic(
() => import('react-notion-x/build/third-party/modal').then((m) => m.Modal),
{
ssr: false
}
)
function Tweet({ id }: { id: string }) {
return <TweetEmbed tweetId={id} />
}
export function NotionPage({
recordMap,
previewImagesEnabled,
rootPageId,
rootDomain
}: {
recordMap: ExtendedRecordMap
previewImagesEnabled?: boolean
rootPageId?: string
rootDomain?: string
}) {
const router = useRouter()
if (router.isFallback) {
return <Loading />
}
if (!recordMap) {
return null
}
const title = getPageTitle(recordMap)
// useful for debugging from the dev console
if (typeof window !== 'undefined') {
const keys = Object.keys(recordMap?.block || {})
const block = recordMap?.block?.[keys[0]]?.value
const g = window as any
g.recordMap = recordMap
g.block = block
}
const socialDescription = 'React Notion X Demo'
const socialImage =
'https://react-notion-x-demo.transitivebullsh.it/social.jpg'
return (
<>
<Head>
{socialDescription && (
<>
<meta name='description' content={socialDescription} />
<meta property='og:description' content={socialDescription} />
<meta name='twitter:description' content={socialDescription} />
</>
)}
{socialImage ? (
<>
<meta name='twitter:card' content='summary_large_image' />
<meta name='twitter:image' content={socialImage} />
<meta property='og:image' content={socialImage} />
</>
) : (
<meta name='twitter:card' content='summary' />
)}
<title>{title}</title>
<meta property='og:title' content={title} />
<meta name='twitter:title' content={title} />
<meta name='twitter:creator' content='@transitive_bs' />
<link rel='icon' href='/favicon.ico' />
</Head>
<NotionRenderer
recordMap={recordMap}
fullPage={true}
darkMode={false}
rootDomain={rootDomain}
rootPageId={rootPageId}
previewImages={previewImagesEnabled}
components={{
// NOTE (transitive-bullshit 3/12/2023): I'm disabling next/image for this repo for now because the amount of traffic started costing me hundreds of dollars a month in Vercel image optimization costs. I'll probably re-enable it in the future if I can find a better solution.
// nextLegacyImage: Image,
nextLink: Link,
Code,
Collection,
Equation,
Pdf,
Modal,
Tweet
}}
// NOTE: custom images will only take effect if previewImages is true and
// if the image has a valid preview image defined in recordMap.preview_images[src]
/>
</>
)
}