mirror of
https://github.com/d0zingcat/nextjs-notion-starter-kit.git
synced 2026-05-13 15:09:47 +00:00
👅
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
import { parsePageId } from 'notion-utils'
|
||||
import posthog from 'posthog-js'
|
||||
import { getEnv, getSiteConfig } from './get-config-value'
|
||||
import { NavigationLink } from './site-config'
|
||||
import {
|
||||
PageUrlOverridesInverseMap,
|
||||
PageUrlOverridesMap,
|
||||
@@ -93,6 +94,14 @@ export const navigationStyle: NavigationStyle = getSiteConfig(
|
||||
'default'
|
||||
)
|
||||
|
||||
export const navigationLinks: Array<NavigationLink | null> = getSiteConfig(
|
||||
'navigationLinks',
|
||||
null
|
||||
)
|
||||
|
||||
// Optional site search
|
||||
export const isSearchEnabled: boolean = getSiteConfig('isSearchEnabled', true)
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// Optional redis instance for persisting preview images
|
||||
|
||||
@@ -12,11 +12,13 @@ const uuid = !!includeNotionIdInUrls
|
||||
export const mapPageUrl =
|
||||
(site: Site, recordMap: ExtendedRecordMap, searchParams: URLSearchParams) =>
|
||||
(pageId = '') => {
|
||||
if (uuidToId(pageId) === site.rootNotionPageId) {
|
||||
const pageUuid = parsePageId(pageId, { uuid: true })
|
||||
|
||||
if (uuidToId(pageUuid) === site.rootNotionPageId) {
|
||||
return createUrl('/', searchParams)
|
||||
} else {
|
||||
return createUrl(
|
||||
`/${getCanonicalPageId(pageId, recordMap, { uuid })}`,
|
||||
`/${getCanonicalPageId(pageUuid, recordMap, { uuid })}`,
|
||||
searchParams
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,15 +1,46 @@
|
||||
import pMap from 'p-map'
|
||||
import { ExtendedRecordMap, SearchParams, SearchResults } from 'notion-types'
|
||||
import { mergeRecordMaps } from 'notion-utils'
|
||||
|
||||
import { notion } from './notion-api'
|
||||
import { getPreviewImageMap } from './preview-images'
|
||||
import { getTweetAstMap } from './tweet-embeds'
|
||||
import {
|
||||
isPreviewImageSupportEnabled,
|
||||
isTweetEmbedSupportEnabled
|
||||
isTweetEmbedSupportEnabled,
|
||||
navigationStyle,
|
||||
navigationLinks
|
||||
} from './config'
|
||||
|
||||
export async function getPage(pageId: string): Promise<ExtendedRecordMap> {
|
||||
const recordMap = await notion.getPage(pageId)
|
||||
let recordMap = await notion.getPage(pageId)
|
||||
|
||||
if (navigationStyle !== 'default') {
|
||||
const navigationLinkPageIds = (navigationLinks || [])
|
||||
.map((link) => link.pageId)
|
||||
.filter(Boolean)
|
||||
|
||||
if (navigationLinkPageIds.length) {
|
||||
const navigationLinkRecordMaps: ExtendedRecordMap[] = await pMap(
|
||||
navigationLinkPageIds,
|
||||
async (navigationLinkPageId) =>
|
||||
notion.getPage(navigationLinkPageId, {
|
||||
fetchMissingBlocks: false,
|
||||
fetchCollections: false,
|
||||
signFileUrls: false
|
||||
}),
|
||||
{
|
||||
concurrency: 4
|
||||
}
|
||||
)
|
||||
|
||||
recordMap = navigationLinkRecordMaps.reduce(
|
||||
(map, navigationLinkRecordMap) =>
|
||||
mergeRecordMaps(map, navigationLinkRecordMap),
|
||||
recordMap
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (isPreviewImageSupportEnabled) {
|
||||
const previewImageMap = await getPreviewImageMap(recordMap)
|
||||
|
||||
@@ -21,12 +21,20 @@ export interface SiteConfig {
|
||||
isPreviewImageSupportEnabled?: boolean
|
||||
isTweetEmbedSupportEnabled?: boolean
|
||||
isRedisEnabled?: boolean
|
||||
isSearchEnabled?: boolean
|
||||
|
||||
includeNotionIdInUrls?: boolean
|
||||
pageUrlOverrides?: types.PageUrlOverridesMap
|
||||
pageUrlAdditions?: types.PageUrlOverridesMap
|
||||
|
||||
navigationStyle?: types.NavigationStyle
|
||||
navigationLinks?: Array<NavigationLink>
|
||||
}
|
||||
|
||||
export interface NavigationLink {
|
||||
title: string
|
||||
pageId?: string
|
||||
url?: string
|
||||
}
|
||||
|
||||
export const siteConfig = (config: SiteConfig): SiteConfig => {
|
||||
|
||||
17
lib/types.ts
17
lib/types.ts
@@ -67,20 +67,3 @@ export interface PageUrlOverridesInverseMap {
|
||||
// (this overrides the built-in URL path generation for these pages)
|
||||
[pageId: string]: string
|
||||
}
|
||||
|
||||
export interface PreviewImage {
|
||||
url: string
|
||||
originalWidth: number
|
||||
originalHeight: number
|
||||
width: number
|
||||
height: number
|
||||
type: string
|
||||
dataURIBase64: string
|
||||
|
||||
error?: string
|
||||
statusCode?: number
|
||||
}
|
||||
|
||||
export interface PreviewImageMap {
|
||||
[url: string]: PreviewImage
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user