feat: add support for includeNotionIdInUrls

This commit is contained in:
Travis Fischer
2021-02-03 20:47:41 -05:00
parent 1910302874
commit 8c7308e183
3 changed files with 15 additions and 6 deletions

View File

@@ -8,7 +8,6 @@
import { parsePageId } from 'notion-utils'
import { getSiteConfig, getEnv } from './get-config-value'
// where it all starts -- the site's root Notion page
export const rootNotionPageId: string = parsePageId(
getSiteConfig('rootNotionPageId', 'ROOT_NOTION_PAGE_ID'),
{ uuid: false }
@@ -101,11 +100,18 @@ export const isPreviewImageSupportEnabled: boolean = getSiteConfig(
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',
'INCLUDE_NOTION_ID_IN_URLS',
!!isDev
)
// ----------------------------------------------------------------------------
export const isServer = typeof window === 'undefined'
export const port = getEnv('PORT', '3000')

View File

@@ -2,8 +2,11 @@ import pMemoize from 'p-memoize'
import { getAllPagesInSpace, getCanonicalPageId } from 'notion-utils'
import * as types from './types'
import { includeNotionIdInUrls } from './config'
import { getPage } from './notion'
const uuid = !!includeNotionIdInUrls
export const getAllPages = pMemoize(getAllPagesImpl, { maxAge: 60000 * 5 })
export async function getAllPagesImpl(
@@ -24,7 +27,7 @@ export async function getAllPagesImpl(
}
const canonicalPageId = getCanonicalPageId(pageId, recordMap, {
uuid: false
uuid
})
if (map[canonicalPageId]) {

View File

@@ -1,10 +1,10 @@
import * as types from './types'
import { isDev } from './config'
import { includeNotionIdInUrls } from './config'
import { getCanonicalPageId, uuidToId, parsePageId } from 'notion-utils'
// include UUIDs in page URLs during local development but not in production
// (they're nice for debugging and speed up local dev)
const uuid = !!isDev
const uuid = !!includeNotionIdInUrls
export const mapPageUrl = (
site: types.Site,