This commit is contained in:
Travis Fischer
2021-02-03 21:01:28 -05:00
parent 8c7308e183
commit 12b30130f2
2 changed files with 27 additions and 51 deletions

View File

@@ -9,7 +9,7 @@ import { parsePageId } from 'notion-utils'
import { getSiteConfig, getEnv } from './get-config-value'
export const rootNotionPageId: string = parsePageId(
getSiteConfig('rootNotionPageId', 'ROOT_NOTION_PAGE_ID'),
getSiteConfig('rootNotionPageId'),
{ uuid: false }
)
@@ -19,84 +19,57 @@ if (!rootNotionPageId) {
// if you want to restrict pages to a single notion workspace (optional)
export const rootNotionSpaceId: string | null = parsePageId(
getSiteConfig('rootNotionSpaceId', 'ROOT_NOTION_SPACE_ID', null),
getSiteConfig('rootNotionSpaceId', null),
{ uuid: true }
)
// general site config
export const name: string = getSiteConfig('name', 'SITE_NAME')
export const author: string = getSiteConfig('author', 'SITE_AUTHOR')
export const domain: string = getSiteConfig('domain', 'SITE_DOMAIN')
export const description: string = getSiteConfig(
'description',
'SITE_DESCRIPTION',
'Notion Blog'
)
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')
// social accounts
export const twitter: string | null = getSiteConfig(
'twitter',
'SITE_TWITTER',
null
)
export const github: string | null = getSiteConfig(
'github',
'SITE_GITHUB',
null
)
export const linkedin: string | null = getSiteConfig(
'linkedin',
'SITE_LINKEDIN',
null
)
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',
'SOCIAL_IMAGE_TITLE',
null
)
export const socialImageSubtitle: string | null = getSiteConfig(
'socialImageSubtitle',
'SOCIAL_IMAGE_SUBTITLE',
null
)
// default notion values for site-wide consistency (optional; may be overridden on a per-page basis)
export const defaultPageIcon: string | null = getSiteConfig(
'defaultPageIcon',
'DEFAULT_PAGE_ICON',
null
)
export const defaultPageCover: string | null = getSiteConfig(
'defaultPageCover',
'DEFAULT_PAGE_COVER',
null
)
export const defaultPageCoverPosition: number = getSiteConfig(
'defaultPageCoverPosition',
null,
0.5
)
// Optional utteranc.es comments via GitHub issue comments
export const utterancesGitHubRepo: string | null = getSiteConfig(
'utterancesGitHubRepo',
'UTTERANCES_GITHUB_REPO',
null
)
// Optional image CDN host to proxy all image requests through
export const imageCDNHost: string | null = getSiteConfig(
'imageCDNHost',
'IMAGE_CDN_HOST',
null
)
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',
null,
false
)
@@ -106,7 +79,6 @@ export const isDev =
// where it all starts -- the site's root Notion page
export const includeNotionIdInUrls: boolean = getSiteConfig(
'includeNotionIdInUrls',
'INCLUDE_NOTION_ID_IN_URLS',
!!isDev
)

View File

@@ -1,23 +1,27 @@
import siteConfig from '../site.config'
import rawSiteConfig from '../site.config'
if (!siteConfig) {
if (!rawSiteConfig) {
throw new Error(`Config error: invalid site.config.js`)
}
export function getSiteConfig<T>(
key: string,
envKey?: string,
defaultValue?: T
): T {
if (envKey) {
// allow environment variables to override site.config.js (optional)
const envValue = process.env[envKey]
// TODO: allow environment variables to override site.config.js
let siteConfigOverrides
if (envValue !== undefined) {
return (envValue as unknown) as T
}
try {
if (process.env.NEXT_PUBLIC_SITE_CONFIG) {
siteConfigOverrides = JSON.parse(process.env.NEXT_PUBLIC_SITE_CONFIG)
}
} catch (err) {
console.error('Invalid config "NEXT_PUBLIC_SITE_CONFIG" failed to parse')
throw err
}
const siteConfig = {
...rawSiteConfig,
...siteConfigOverrides
}
export function getSiteConfig<T>(key: string, defaultValue?: T): T {
const value = siteConfig[key]
if (value !== undefined) {