Skip to content

Commit

Permalink
feat: add support for includeNotionIdInUrls
Browse files Browse the repository at this point in the history
  • Loading branch information
transitive-bullshit committed Feb 4, 2021
1 parent 1910302 commit 8c7308e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
12 changes: 9 additions & 3 deletions lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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')
Expand Down
5 changes: 4 additions & 1 deletion lib/get-all-pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -24,7 +27,7 @@ export async function getAllPagesImpl(
}

const canonicalPageId = getCanonicalPageId(pageId, recordMap, {
uuid: false
uuid
})

if (map[canonicalPageId]) {
Expand Down
4 changes: 2 additions & 2 deletions lib/map-page-url.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit 8c7308e

Please sign in to comment.