5
5
* for optional depenencies.
6
6
*/
7
7
8
- import { parsePageId } from 'notion-utils'
9
- import posthog from 'posthog-js'
10
- import { getEnv , getSiteConfig } from './get-config-value'
11
- import { NavigationLink } from './site-config'
12
- import {
13
- PageUrlOverridesInverseMap ,
14
- PageUrlOverridesMap ,
15
- NavigationStyle ,
16
- Site
17
- } from './types'
18
-
19
- export const rootNotionPageId : string = parsePageId (
20
- getSiteConfig ( 'rootNotionPageId' ) ,
21
- { uuid : false }
22
- )
23
-
24
- if ( ! rootNotionPageId ) {
25
- throw new Error ( 'Config error invalid "rootNotionPageId"' )
26
- }
27
-
28
- // if you want to restrict pages to a single notion workspace (optional)
29
- export const rootNotionSpaceId : string | null = parsePageId (
30
- getSiteConfig ( 'rootNotionSpaceId' , null ) ,
31
- { uuid : true }
32
- )
33
-
34
- export const pageUrlOverrides = cleanPageUrlMap (
35
- getSiteConfig ( 'pageUrlOverrides' , { } ) || { } ,
36
- { label : 'pageUrlOverrides' }
37
- )
38
-
39
- export const pageUrlAdditions = cleanPageUrlMap (
40
- getSiteConfig ( 'pageUrlAdditions' , { } ) || { } ,
41
- { label : 'pageUrlAdditions' }
42
- )
43
-
44
- export const inversePageUrlOverrides = invertPageUrlOverrides ( pageUrlOverrides )
45
-
46
- export const environment = process . env . NODE_ENV || 'development'
47
- export const isDev = environment === 'development'
48
-
49
- // general site config
50
- export const name : string = getSiteConfig ( 'name' )
51
- export const author : string = getSiteConfig ( 'author' )
52
- export const domain : string = getSiteConfig ( 'domain' )
53
- export const description : string = getSiteConfig ( 'description' , 'Notion Blog' )
54
- export const language : string = getSiteConfig ( 'language' , 'en' )
55
-
56
- // social accounts
57
- export const twitter : string | null = getSiteConfig ( 'twitter' , null )
58
- export const github : string | null = getSiteConfig ( 'github' , null )
59
- export const youtube : string | null = getSiteConfig ( 'youtube' , null )
60
- export const linkedin : string | null = getSiteConfig ( 'linkedin' , null )
61
- export const zhihu : string | null = getSiteConfig ( 'zhihu' , null )
62
-
63
- // default notion values for site-wide consistency (optional; may be overridden on a per-page basis)
64
- export const defaultPageIcon : string | null = getSiteConfig (
65
- 'defaultPageIcon' ,
66
- null
67
- )
68
- export const defaultPageCover : string | null = getSiteConfig (
69
- 'defaultPageCover' ,
70
- null
71
- )
72
- export const defaultPageCoverPosition : number = getSiteConfig (
73
- 'defaultPageCoverPosition' ,
74
- 0.5
75
- )
76
-
77
- // Optional whether or not to enable support for LQIP preview images
78
- export const isPreviewImageSupportEnabled : boolean = getSiteConfig (
79
- 'isPreviewImageSupportEnabled' ,
80
- false
81
- )
82
-
83
- // Optional whether or not to include the Notion ID in page URLs or just use slugs
84
- export const includeNotionIdInUrls : boolean = getSiteConfig (
85
- 'includeNotionIdInUrls' ,
86
- ! ! isDev
87
- )
88
-
89
- export const navigationStyle : NavigationStyle = getSiteConfig (
90
- 'navigationStyle' ,
91
- 'default'
92
- )
93
-
94
- export const navigationLinks : Array < NavigationLink | null > = getSiteConfig (
95
- 'navigationLinks' ,
96
- null
97
- )
98
-
99
- // Optional site search
100
- export const isSearchEnabled : boolean = getSiteConfig ( 'isSearchEnabled' , true )
101
-
102
- // ----------------------------------------------------------------------------
103
-
104
- // Optional redis instance for persisting preview images
105
- export const isRedisEnabled : boolean =
106
- getSiteConfig ( 'isRedisEnabled' , false ) || ! ! getEnv ( 'REDIS_ENABLED' , null )
107
-
108
- // (if you want to enable redis, only REDIS_HOST and REDIS_PASSWORD are required)
109
- // we recommend that you store these in a local `.env` file
110
- export const redisHost : string | null = getEnv ( 'REDIS_HOST' , null )
111
- export const redisPassword : string | null = getEnv ( 'REDIS_PASSWORD' , null )
112
- export const redisUser : string = getEnv ( 'REDIS_USER' , 'default' )
113
- export const redisUrl = getEnv (
114
- 'REDIS_URL' ,
115
- `redis://${ redisUser } :${ redisPassword } @${ redisHost } `
116
- )
117
- export const redisNamespace : string | null = getEnv (
118
- 'REDIS_NAMESPACE' ,
119
- 'preview-images'
120
- )
121
-
122
- // ----------------------------------------------------------------------------
123
-
124
- export const isServer = typeof window === 'undefined'
125
-
126
- export const port = getEnv ( 'PORT' , '3000' )
127
- export const host = isDev ? `http://localhost:${ port } ` : `https://${ domain } `
128
-
129
- export const apiBaseUrl = `/api`
130
-
131
- export const api = {
132
- searchNotion : `${ apiBaseUrl } /search-notion` ,
133
- getSocialImage : `${ apiBaseUrl } /social-image`
134
- }
135
-
136
- // ----------------------------------------------------------------------------
137
-
138
- export const site : Site = {
139
- domain,
140
- name,
141
- rootNotionPageId,
142
- rootNotionSpaceId,
143
- description
144
- }
145
-
146
- export const fathomId = isDev ? null : process . env . NEXT_PUBLIC_FATHOM_ID
147
- export const fathomConfig = fathomId
148
- ? {
149
- excludedDomains : [ 'localhost' , 'localhost:3000' ]
150
- }
151
- : undefined
152
-
153
- export const posthogId = process . env . NEXT_PUBLIC_POSTHOG_ID
154
- export const posthogConfig : posthog . Config = {
155
- api_host : 'https://app.posthog.com'
156
- }
157
-
158
- function cleanPageUrlMap (
159
- pageUrlMap : PageUrlOverridesMap ,
160
- {
161
- label
162
- } : {
163
- label : string
164
- }
165
- ) : PageUrlOverridesMap {
166
- return Object . keys ( pageUrlMap ) . reduce ( ( acc , uri ) => {
167
- const pageId = pageUrlMap [ uri ]
168
- const uuid = parsePageId ( pageId , { uuid : false } )
169
-
170
- if ( ! uuid ) {
171
- throw new Error ( `Invalid ${ label } page id "${ pageId } "` )
172
- }
173
-
174
- if ( ! uri ) {
175
- throw new Error ( `Missing ${ label } value for page "${ pageId } "` )
176
- }
177
-
178
- if ( ! uri . startsWith ( '/' ) ) {
179
- throw new Error (
180
- `Invalid ${ label } value for page "${ pageId } ": value "${ uri } " should be a relative URI that starts with "/"`
181
- )
182
- }
183
-
184
- const path = uri . slice ( 1 )
185
-
186
- return {
187
- ...acc ,
188
- [ path ] : uuid
189
- }
190
- } , { } )
191
- }
192
-
193
- function invertPageUrlOverrides (
194
- pageUrlOverrides : PageUrlOverridesMap
195
- ) : PageUrlOverridesInverseMap {
196
- return Object . keys ( pageUrlOverrides ) . reduce ( ( acc , uri ) => {
197
- const pageId = pageUrlOverrides [ uri ]
198
-
199
- return {
200
- ...acc ,
201
- [ pageId ] : uri
202
- }
203
- } , { } )
204
- }
205
-
8
+ import { parsePageId } from 'notion-utils'
9
+ import posthog from 'posthog-js'
10
+ import { getEnv , getSiteConfig } from './get-config-value'
11
+ import { NavigationLink } from './site-config'
12
+ import {
13
+ PageUrlOverridesInverseMap ,
14
+ PageUrlOverridesMap ,
15
+ NavigationStyle ,
16
+ Site
17
+ } from './types'
18
+
19
+ export const rootNotionPageId : string = parsePageId (
20
+ getSiteConfig ( 'rootNotionPageId' ) ,
21
+ { uuid : false }
22
+ )
23
+
24
+ if ( ! rootNotionPageId ) {
25
+ throw new Error ( 'Config error invalid "rootNotionPageId"' )
26
+ }
27
+
28
+ // if you want to restrict pages to a single notion workspace (optional)
29
+ export const rootNotionSpaceId : string | null = parsePageId (
30
+ getSiteConfig ( 'rootNotionSpaceId' , null ) ,
31
+ { uuid : true }
32
+ )
33
+
34
+ export const pageUrlOverrides = cleanPageUrlMap (
35
+ getSiteConfig ( 'pageUrlOverrides' , { } ) || { } ,
36
+ { label : 'pageUrlOverrides' }
37
+ )
38
+
39
+ export const pageUrlAdditions = cleanPageUrlMap (
40
+ getSiteConfig ( 'pageUrlAdditions' , { } ) || { } ,
41
+ { label : 'pageUrlAdditions' }
42
+ )
43
+
44
+ export const inversePageUrlOverrides = invertPageUrlOverrides ( pageUrlOverrides )
45
+
46
+ export const environment = process . env . NODE_ENV || 'development'
47
+ export const isDev = environment === 'development'
48
+
49
+ // general site config
50
+ export const name : string = getSiteConfig ( 'name' )
51
+ export const author : string = getSiteConfig ( 'author' )
52
+ export const domain : string = getSiteConfig ( 'domain' )
53
+ export const description : string = getSiteConfig ( 'description' , 'Notion Blog' )
54
+ export const language : string = getSiteConfig ( 'language' , 'en' )
55
+
56
+ // social accounts
57
+ export const twitter : string | null = getSiteConfig ( 'twitter' , null )
58
+ export const github : string | null = getSiteConfig ( 'github' , null )
59
+ export const youtube : string | null = getSiteConfig ( 'youtube' , null )
60
+ export const linkedin : string | null = getSiteConfig ( 'linkedin' , null )
61
+ export const zhihu : string | null = getSiteConfig ( 'zhihu' , null )
62
+
63
+ // default notion values for site-wide consistency (optional; may be overridden on a per-page basis)
64
+ export const defaultPageIcon : string | null = getSiteConfig (
65
+ 'defaultPageIcon' ,
66
+ null
67
+ )
68
+ export const defaultPageCover : string | null = getSiteConfig (
69
+ 'defaultPageCover' ,
70
+ null
71
+ )
72
+ export const defaultPageCoverPosition : number = getSiteConfig (
73
+ 'defaultPageCoverPosition' ,
74
+ 0.5
75
+ )
76
+
77
+ // Optional whether or not to enable support for LQIP preview images
78
+ export const isPreviewImageSupportEnabled : boolean = getSiteConfig (
79
+ 'isPreviewImageSupportEnabled' ,
80
+ false
81
+ )
82
+
83
+ // Optional whether or not to include the Notion ID in page URLs or just use slugs
84
+ export const includeNotionIdInUrls : boolean = getSiteConfig (
85
+ 'includeNotionIdInUrls' ,
86
+ ! ! isDev
87
+ )
88
+
89
+ export const navigationStyle : NavigationStyle = getSiteConfig (
90
+ 'navigationStyle' ,
91
+ 'default'
92
+ )
93
+
94
+ export const navigationLinks : Array < NavigationLink | null > = getSiteConfig (
95
+ 'navigationLinks' ,
96
+ null
97
+ )
98
+
99
+ // Optional site search
100
+ export const isSearchEnabled : boolean = getSiteConfig ( 'isSearchEnabled' , true )
101
+
102
+ // ----------------------------------------------------------------------------
103
+
104
+ // Optional redis instance for persisting preview images
105
+ export const isRedisEnabled : boolean =
106
+ getSiteConfig ( 'isRedisEnabled' , false ) || ! ! getEnv ( 'REDIS_ENABLED' , null )
107
+
108
+ // (if you want to enable redis, only REDIS_HOST and REDIS_PASSWORD are required)
109
+ // we recommend that you store these in a local `.env` file
110
+ export const redisHost : string | null = getEnv ( 'REDIS_HOST' , null )
111
+ export const redisPassword : string | null = getEnv ( 'REDIS_PASSWORD' , null )
112
+ export const redisUser : string = getEnv ( 'REDIS_USER' , 'default' )
113
+ export const redisUrl = getEnv (
114
+ 'REDIS_URL' ,
115
+ `redis://${ redisUser } :${ redisPassword } @${ redisHost } `
116
+ )
117
+ export const redisNamespace : string | null = getEnv (
118
+ 'REDIS_NAMESPACE' ,
119
+ 'preview-images'
120
+ )
121
+
122
+ // ----------------------------------------------------------------------------
123
+
124
+ export const isServer = typeof window === 'undefined'
125
+
126
+ export const port = getEnv ( 'PORT' , '3000' )
127
+ export const host = isDev ? `http://localhost:${ port } ` : `https://${ domain } `
128
+
129
+ export const apiBaseUrl = `/api`
130
+
131
+ export const api = {
132
+ searchNotion : `${ apiBaseUrl } /search-notion` ,
133
+ getSocialImage : `${ apiBaseUrl } /social-image`
134
+ }
135
+
136
+ // ----------------------------------------------------------------------------
137
+
138
+ export const site : Site = {
139
+ domain,
140
+ name,
141
+ rootNotionPageId,
142
+ rootNotionSpaceId,
143
+ description
144
+ }
145
+
146
+ export const fathomId = isDev ? null : process . env . NEXT_PUBLIC_FATHOM_ID
147
+ export const fathomConfig = fathomId
148
+ ? {
149
+ excludedDomains : [ 'localhost' , 'localhost:3000' ]
150
+ }
151
+ : undefined
152
+
153
+ export const posthogId = process . env . NEXT_PUBLIC_POSTHOG_ID
154
+ export const posthogConfig : posthog . Config = {
155
+ api_host : 'https://app.posthog.com'
156
+ }
157
+
158
+ function cleanPageUrlMap (
159
+ pageUrlMap : PageUrlOverridesMap ,
160
+ {
161
+ label
162
+ } : {
163
+ label : string
164
+ }
165
+ ) : PageUrlOverridesMap {
166
+ return Object . keys ( pageUrlMap ) . reduce ( ( acc , uri ) => {
167
+ const pageId = pageUrlMap [ uri ]
168
+ const uuid = parsePageId ( pageId , { uuid : false } )
169
+
170
+ if ( ! uuid ) {
171
+ throw new Error ( `Invalid ${ label } page id "${ pageId } "` )
172
+ }
173
+
174
+ if ( ! uri ) {
175
+ throw new Error ( `Missing ${ label } value for page "${ pageId } "` )
176
+ }
177
+
178
+ if ( ! uri . startsWith ( '/' ) ) {
179
+ throw new Error (
180
+ `Invalid ${ label } value for page "${ pageId } ": value "${ uri } " should be a relative URI that starts with "/"`
181
+ )
182
+ }
183
+
184
+ const path = uri . slice ( 1 )
185
+
186
+ return {
187
+ ...acc ,
188
+ [ path ] : uuid
189
+ }
190
+ } , { } )
191
+ }
192
+
193
+ function invertPageUrlOverrides (
194
+ pageUrlOverrides : PageUrlOverridesMap
195
+ ) : PageUrlOverridesInverseMap {
196
+ return Object . keys ( pageUrlOverrides ) . reduce ( ( acc , uri ) => {
197
+ const pageId = pageUrlOverrides [ uri ]
198
+
199
+ return {
200
+ ...acc ,
201
+ [ pageId ] : uri
202
+ }
203
+ } , { } )
204
+ }
0 commit comments