forked from amanintech/amansharma.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.ts
234 lines (189 loc) · 6.3 KB
/
config.ts
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/**
* Site-wide app configuration.
*
* This file pulls from the root "site.config.js" as well as environment variables
* for optional depenencies.
*/
import { parsePageId } from 'notion-utils'
import { getSiteConfig, getEnv } from './get-config-value'
import { PageUrlOverridesMap, PageUrlOverridesInverseMap } from './types'
export const rootNotionPageId: string = parsePageId(
getSiteConfig('rootNotionPageId'),
{ uuid: false }
)
if (!rootNotionPageId) {
throw new Error('Config error invalid "rootNotionPageId"')
}
// if you want to restrict pages to a single notion workspace (optional)
export const rootNotionSpaceId: string | null = parsePageId(
getSiteConfig('rootNotionSpaceId', null),
{ uuid: true }
)
export const pageUrlOverrides = cleanPageUrlMap(
getSiteConfig('pageUrlOverrides', {}) || {},
'pageUrlOverrides'
)
export const inversePageUrlOverrides = invertPageUrlOverrides(pageUrlOverrides)
export const fontFamily = getSiteConfig('fontFamily', null)
export const pageUrlAdditions = cleanPageUrlMap(
getSiteConfig('pageUrlAdditions', {}) || {},
'pageUrlAdditions'
)
// general site config
export const name: string = getSiteConfig('name')
export const author: string = getSiteConfig('author')
export const domain: string = getSiteConfig('domain')
export const description: string = getSiteConfig('description', 'Notion Blog')
export const showGithubRibbon: boolean = getSiteConfig(
'showGithubRibbon',
false
)
export const showPageAsideSocials: boolean = getSiteConfig(
'showPageAsideSocials',
false
)
// social accounts
export const twitter: string | null = getSiteConfig('twitter', null)
export const github: string | null = getSiteConfig('github', null)
export const linkedin: string | null = getSiteConfig('linkedin', null)
export const socialImageTitle: string | null = getSiteConfig(
'socialImageTitle',
null
)
export const socialImageSubtitle: string | null = getSiteConfig(
'socialImageSubtitle',
null
)
// default notion values for site-wide consistency (optional; may be overridden on a per-page basis)
export const defaultPageIcon: string | null = getSiteConfig(
'defaultPageIcon',
null
)
export const defaultPageCover: string | null = getSiteConfig(
'defaultPageCover',
null
)
export const defaultPageCoverPosition: number = getSiteConfig(
'defaultPageCoverPosition',
0.5
)
// Optional utteranc.es comments via GitHub issue comments
export const utterancesGitHubRepo: string | null = getSiteConfig(
'utterancesGitHubRepo',
null
)
export const utterancesGitHubLabel: string | null = getSiteConfig(
'utterancesGitHubLabel',
null
)
// Optional image CDN host to proxy all image requests through
export const imageCDNHost: string | null = getSiteConfig('imageCDNHost', null)
// Optional whether or not to enable support for LQIP preview images
// (requires a Google Firebase collection)
export const isPreviewImageSupportEnabled: boolean = getSiteConfig(
'isPreviewImageSupportEnabled',
false
)
export const isDev =
process.env.NODE_ENV === 'development' || !process.env.NODE_ENV
// where it all starts -- the site's root Notion page
export const includeNotionIdInUrls: boolean = getSiteConfig(
'includeNotionIdInUrls',
!!isDev
)
// ----------------------------------------------------------------------------
export const isServer = typeof window === 'undefined'
export const port = getEnv('PORT', '3000')
export const host = isDev ? `http://localhost:${port}` : `https://${domain}`
export const apiBaseUrl = `${host}/api`
export const api = {
createPreviewImage: `${apiBaseUrl}/create-preview-image`,
searchNotion: `${apiBaseUrl}/search-notion`
}
// ----------------------------------------------------------------------------
export const fathomId = isDev ? null : process.env.NEXT_PUBLIC_FATHOM_ID
const fathomDomain = isDev ? null : process.env.NEXT_PUBLIC_FATHOM_DOMAIN
export const fathomConfig = fathomId
? {
url: fathomDomain
? `https://${fathomDomain}/script.js`
: 'https://cdn.usefathom.com/script.js',
excludedDomains: ['localhost', 'localhost:3000']
}
: undefined
const defaultEnvValueForPreviewImageSupport =
isPreviewImageSupportEnabled && isServer ? undefined : null
export const googleProjectId = getEnv(
'GCLOUD_PROJECT',
defaultEnvValueForPreviewImageSupport
)
export const googleApplicationCredentials = getGoogleApplicationCredentials()
export const firebaseCollectionImages = getEnv(
'FIREBASE_COLLECTION_IMAGES',
defaultEnvValueForPreviewImageSupport
)
export const firebaseCollectionPageviews = getEnv(
'FIREBASE_COLLECTION_PAGEVIEWS',
'pageviews'
)
export const firebaseCollectionFeedbacks = getEnv(
'FIREBASE_COLLECTION_FEEDBACKS',
'feedbacks'
)
// this hack is necessary because vercel doesn't support secret files so we need to encode our google
// credentials a base64-encoded string of the JSON-ified content
function getGoogleApplicationCredentials() {
if (!isPreviewImageSupportEnabled || !isServer) {
return null
}
try {
const googleApplicationCredentialsBase64 = getEnv(
'GOOGLE_APPLICATION_CREDENTIALS',
defaultEnvValueForPreviewImageSupport
)
return JSON.parse(
Buffer.from(googleApplicationCredentialsBase64, 'base64').toString()
)
} catch (err) {
console.error(
'Firebase config error: invalid "GOOGLE_APPLICATION_CREDENTIALS" should be base64-encoded JSON\n'
)
throw err
}
}
function cleanPageUrlMap(
pageUrlMap: PageUrlOverridesMap,
label: string
): PageUrlOverridesMap {
return Object.keys(pageUrlMap).reduce((acc, uri) => {
const pageId = pageUrlMap[uri]
const uuid = parsePageId(pageId, { uuid: false })
if (!uuid) {
throw new Error(`Invalid ${label} page id "${pageId}"`)
}
if (!uri) {
throw new Error(`Missing ${label} value for page "${pageId}"`)
}
if (!uri.startsWith('/')) {
throw new Error(
`Invalid ${label} value for page "${pageId}": value "${uri}" should be a relative URI that starts with "/"`
)
}
const path = uri.slice(1)
return {
...acc,
[path]: uuid
}
}, {})
}
function invertPageUrlOverrides(
pageUrlOverrides: PageUrlOverridesMap
): PageUrlOverridesInverseMap {
return Object.keys(pageUrlOverrides).reduce((acc, uri) => {
const pageId = pageUrlOverrides[uri]
return {
...acc,
[pageId]: uri
}
}, {})
}