mirror of
https://github.com/d0zingcat/nextjs-notion-starter-kit.git
synced 2026-05-13 15:09:47 +00:00
feat: remove notion page ids from URLs
This commit is contained in:
@@ -25,20 +25,17 @@ export async function getAllPagesImpl(
|
||||
|
||||
if (map[canonicalPageId]) {
|
||||
console.error(
|
||||
'duplicate canonical page id',
|
||||
'error duplicate canonical page id',
|
||||
canonicalPageId,
|
||||
pageId,
|
||||
map[canonicalPageId].pageId
|
||||
map[canonicalPageId]
|
||||
)
|
||||
|
||||
return map
|
||||
} else {
|
||||
return {
|
||||
...map,
|
||||
[canonicalPageId]: {
|
||||
pageId,
|
||||
recordMap
|
||||
}
|
||||
[canonicalPageId]: pageId
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -13,40 +13,33 @@ export async function resolveNotionPage(domain: string, rawPageId?: string) {
|
||||
if (rawPageId && rawPageId !== 'index') {
|
||||
pageId = parsePageId(rawPageId)
|
||||
|
||||
// handle mapping user-friendly canonical page paths to Notion page IDs
|
||||
// e.g., /developer-x-entrepreneur versus /71201624b204481f862630ea25ce62fe
|
||||
if (!pageId) {
|
||||
if (pageId) {
|
||||
const resources = await Promise.all([
|
||||
getSiteForDomain(domain),
|
||||
getPage(pageId)
|
||||
])
|
||||
|
||||
site = resources[0]
|
||||
recordMap = resources[1]
|
||||
} else {
|
||||
// handle mapping of user-friendly canonical page paths to Notion page IDs
|
||||
// e.g., /developer-x-entrepreneur versus /71201624b204481f862630ea25ce62fe
|
||||
const siteMaps = await getSiteMaps()
|
||||
const siteMap = siteMaps[0]
|
||||
console.log(siteMap)
|
||||
pageId = siteMap.canonicalPageMap[pageId]?.pageId
|
||||
pageId = siteMap.canonicalPageMap[rawPageId]
|
||||
|
||||
if (!pageId) {
|
||||
if (pageId) {
|
||||
site = await getSiteForDomain(domain)
|
||||
recordMap = siteMap.pageMap[pageId]
|
||||
} else {
|
||||
return {
|
||||
error: {
|
||||
message: `Invalid notion page ID "${rawPageId}"`,
|
||||
message: `Not found "${rawPageId}"`,
|
||||
statusCode: 404
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!pageId) {
|
||||
return {
|
||||
error: {
|
||||
message: `Invalid notion page ID "${rawPageId}"`,
|
||||
statusCode: 404
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const resources = await Promise.all([
|
||||
getSiteForDomain(domain),
|
||||
getPage(pageId)
|
||||
])
|
||||
|
||||
site = resources[0]
|
||||
recordMap = resources[1]
|
||||
} else {
|
||||
site = await getSiteForDomain(domain)
|
||||
pageId = site.rootNotionPageId
|
||||
|
||||
@@ -52,10 +52,7 @@ export interface SiteMap {
|
||||
}
|
||||
|
||||
export interface CanonicalPageMap {
|
||||
[canonicalPagePath: string]: {
|
||||
pageId: string
|
||||
recordMap: ExtendedRecordMap | null
|
||||
}
|
||||
[canonicalPageId: string]: string
|
||||
}
|
||||
|
||||
export interface PreviewImage {
|
||||
|
||||
Reference in New Issue
Block a user