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:
@@ -1,4 +1,5 @@
|
||||
import pMap from 'p-map'
|
||||
import pMemoize from 'p-memoize'
|
||||
import { ExtendedRecordMap, SearchParams, SearchResults } from 'notion-types'
|
||||
import { mergeRecordMaps } from 'notion-utils'
|
||||
|
||||
@@ -12,16 +13,14 @@ import {
|
||||
navigationLinks
|
||||
} from './config'
|
||||
|
||||
export async function getPage(pageId: string): Promise<ExtendedRecordMap> {
|
||||
let recordMap = await notion.getPage(pageId)
|
||||
|
||||
if (navigationStyle !== 'default') {
|
||||
const getNavigationLinkPages = pMemoize(
|
||||
async (): Promise<ExtendedRecordMap[]> => {
|
||||
const navigationLinkPageIds = (navigationLinks || [])
|
||||
.map((link) => link.pageId)
|
||||
.filter(Boolean)
|
||||
|
||||
if (navigationLinkPageIds.length) {
|
||||
const navigationLinkRecordMaps: ExtendedRecordMap[] = await pMap(
|
||||
if (navigationStyle !== 'default' && navigationLinkPageIds.length) {
|
||||
return pMap(
|
||||
navigationLinkPageIds,
|
||||
async (navigationLinkPageId) =>
|
||||
notion.getPage(navigationLinkPageId, {
|
||||
@@ -33,7 +32,22 @@ export async function getPage(pageId: string): Promise<ExtendedRecordMap> {
|
||||
concurrency: 4
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
return []
|
||||
}
|
||||
)
|
||||
|
||||
export async function getPage(pageId: string): Promise<ExtendedRecordMap> {
|
||||
let recordMap = await notion.getPage(pageId)
|
||||
|
||||
if (navigationStyle !== 'default') {
|
||||
// ensure that any pages linked to in the custom navigation header have
|
||||
// their block info fully resolved in the page record map so we know
|
||||
// the page title, slug, etc.
|
||||
const navigationLinkRecordMaps = await getNavigationLinkPages()
|
||||
|
||||
if (navigationLinkRecordMaps?.length) {
|
||||
recordMap = navigationLinkRecordMaps.reduce(
|
||||
(map, navigationLinkRecordMap) =>
|
||||
mergeRecordMaps(map, navigationLinkRecordMap),
|
||||
|
||||
Reference in New Issue
Block a user