forked from transitive-bullshit/nextjs-notion-starter-kit
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import * as React from 'react' | ||
import { GetStaticProps } from 'next' | ||
|
||
import { NotionPage } from '@/components/NotionPage' | ||
import { domain, isDev } from '@/lib/config' | ||
import { getSiteMap } from '@/lib/get-site-map' | ||
import { resolveNotionPage } from '@/lib/resolve-notion-page' | ||
import { PageProps, Params } from '@/lib/types' | ||
|
||
export const getStaticProps: GetStaticProps<PageProps, Params> = async ( | ||
context | ||
) => { | ||
const rawPageId = context.params.pageId as string | ||
|
||
try { | ||
console.error(rawPageId) | ||
const props = await resolveNotionPage(domain, rawPageId) | ||
|
||
return { props, revalidate: 10 } | ||
} catch (err) { | ||
console.error('page error', domain, rawPageId, err) | ||
|
||
// we don't want to publish the error version of this page, so | ||
// let next.js know explicitly that incremental SSG failed | ||
throw err | ||
} | ||
} | ||
|
||
export async function getStaticPaths() { | ||
if (isDev) { | ||
return { | ||
paths: [], | ||
fallback: true | ||
} | ||
} | ||
|
||
const siteMap = await getSiteMap() | ||
|
||
const staticPaths = { | ||
paths: Object.keys(siteMap.canonicalPageMap).map((pageId) => ({ | ||
params: { | ||
pageId | ||
} | ||
})), | ||
// paths: [], | ||
fallback: true | ||
} | ||
|
||
console.log(staticPaths.paths) | ||
return staticPaths | ||
} | ||
|
||
export default function NotionDomainDynamicPage(props) { | ||
return <NotionPage {...props} /> | ||
} |