feat: WIP custom header nav

This commit is contained in:
Travis Fischer
2022-04-07 12:38:58 -04:00
parent 031c41c85b
commit 679131ad22
11 changed files with 97 additions and 19 deletions

View File

@@ -1,14 +1,18 @@
/**
* Site-wide app configuration.
*
* This file pulls from the root "site.config.js" as well as environment variables
* This file pulls from the root "site.config.ts" as well as environment variables
* for optional depenencies.
*/
import { parsePageId } from 'notion-utils'
import posthog from 'posthog-js'
import { getEnv, getSiteConfig } from './get-config-value'
import { PageUrlOverridesInverseMap, PageUrlOverridesMap } from './types'
import {
PageUrlOverridesInverseMap,
PageUrlOverridesMap,
NavigationStyle
} from './types'
export const rootNotionPageId: string = parsePageId(
getSiteConfig('rootNotionPageId'),
@@ -48,9 +52,9 @@ export const description: string = getSiteConfig('description', 'Notion Blog')
// social accounts
export const twitter: string | null = getSiteConfig('twitter', null)
export const zhihu: string | null = getSiteConfig('zhihu', null)
export const github: string | null = getSiteConfig('github', null)
export const linkedin: string | null = getSiteConfig('linkedin', null)
export const zhihu: string | null = getSiteConfig('zhihu', null)
// default notion values for site-wide consistency (optional; may be overridden on a per-page basis)
export const defaultPageIcon: string | null = getSiteConfig(
@@ -78,12 +82,17 @@ export const isTweetEmbedSupportEnabled: boolean = getSiteConfig(
true
)
// where it all starts -- the site's root Notion page
// Optional whether or not to include the Notion ID in page URLs or just use slugs
export const includeNotionIdInUrls: boolean = getSiteConfig(
'includeNotionIdInUrls',
!!isDev
)
export const navigationStyle: NavigationStyle = getSiteConfig(
'navigationStyle',
'default'
)
// ----------------------------------------------------------------------------
// Optional redis instance for persisting preview images

View File

@@ -1,11 +1,12 @@
import rawSiteConfig from '../site.config'
import { SiteConfig } from './site-config'
if (!rawSiteConfig) {
throw new Error(`Config error: invalid site.config.js`)
throw new Error(`Config error: invalid site.config.ts`)
}
// TODO: allow environment variables to override site.config.js
let siteConfigOverrides
// allow environment variables to override site.config.ts
let siteConfigOverrides: SiteConfig
try {
if (process.env.NEXT_PUBLIC_SITE_CONFIG) {
@@ -16,7 +17,7 @@ try {
throw err
}
const siteConfig = {
const siteConfig: SiteConfig = {
...rawSiteConfig,
...siteConfigOverrides
}

34
lib/site-config.ts Normal file
View File

@@ -0,0 +1,34 @@
import * as types from './types'
export interface SiteConfig {
rootNotionPageId: string
rootNotionSpaceId?: string
name: string
domain: string
author: string
description?: string
twitter?: string
github?: string
linkedin?: string
zhihu?: string
defaultPageIcon?: string | null
defaultPageCover?: string | null
defaultPageCoverPosition?: number | null
isPreviewImageSupportEnabled?: boolean
isTweetEmbedSupportEnabled?: boolean
isRedisEnabled?: boolean
includeNotionIdInUrls?: boolean
pageUrlOverrides?: types.PageUrlOverridesMap
pageUrlAdditions?: types.PageUrlOverridesMap
navigationStyle?: types.NavigationStyle
}
export const siteConfig = (config: SiteConfig): SiteConfig => {
return config
}

View File

@@ -2,6 +2,8 @@ import { ExtendedRecordMap, PageMap } from 'notion-types'
export * from 'notion-types'
export type NavigationStyle = 'default' | 'custom'
export interface PageError {
message?: string
statusCode: number