mirror of
https://github.com/d0zingcat/nextjs-notion-starter-kit.git
synced 2026-06-08 23:16:48 +00:00
feat: initial webapp structure from notion2site
This commit is contained in:
57
pages/[pageId].tsx
Normal file
57
pages/[pageId].tsx
Normal file
@@ -0,0 +1,57 @@
|
||||
import React from 'react'
|
||||
import { isDev, domain } from 'lib/env'
|
||||
import { getSiteMaps } from 'lib/get-site-maps'
|
||||
import { resolveNotionPage } from 'lib/resolve-notion-page'
|
||||
import { NotionPage } from 'components'
|
||||
|
||||
export const getStaticProps = async (context) => {
|
||||
const rawPageId = context.params.pageId as string
|
||||
|
||||
try {
|
||||
const props = await resolveNotionPage(domain, rawPageId)
|
||||
|
||||
return { props, revalidate: 10 }
|
||||
} catch (err) {
|
||||
console.error('page error', domain, rawPageId, err)
|
||||
|
||||
return {
|
||||
props: {
|
||||
error: {
|
||||
statusCode: err.statusCode || 500,
|
||||
message: err.message
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function getStaticPaths() {
|
||||
if (isDev) {
|
||||
return {
|
||||
paths: [],
|
||||
fallback: true
|
||||
}
|
||||
}
|
||||
|
||||
const siteMaps = await getSiteMaps()
|
||||
|
||||
const ret = {
|
||||
paths: siteMaps.flatMap((siteMap) =>
|
||||
siteMap.pageIds.map((pageId) => ({
|
||||
params: {
|
||||
domain: siteMap.site.domain,
|
||||
pageId
|
||||
}
|
||||
}))
|
||||
),
|
||||
// paths: [],
|
||||
fallback: true
|
||||
}
|
||||
|
||||
console.log(ret.paths)
|
||||
return ret
|
||||
}
|
||||
|
||||
export default function NotionDomainDynamicPage(props) {
|
||||
return <NotionPage {...props} />
|
||||
}
|
||||
@@ -1,10 +1,19 @@
|
||||
// global styles shared across the entire site
|
||||
import 'styles/global.css'
|
||||
import 'react-notion/styles.css'
|
||||
import 'prismjs/themes/prism-tomorrow.css'
|
||||
import 'rc-dropdown/assets/index.css'
|
||||
import 'katex/dist/katex.min.css'
|
||||
|
||||
import React from 'react'
|
||||
// core styles shared by all of react-notion-x (required)
|
||||
import 'react-notion-x/src/styles.css'
|
||||
|
||||
// used for code syntax highlighting (optional)
|
||||
import 'prismjs/themes/prism-tomorrow.css'
|
||||
|
||||
// used for collection views (optional)
|
||||
import 'rc-dropdown/assets/index.css'
|
||||
|
||||
// used for rendering equations (optional)
|
||||
// import 'katex/dist/katex.min.css'
|
||||
|
||||
import * as React from 'react'
|
||||
import { useEffect } from 'react'
|
||||
import { useRouter } from 'next/router'
|
||||
import { bootstrap } from 'lib/bootstrap-client'
|
||||
|
||||
@@ -1,11 +1,33 @@
|
||||
import * as React from 'react'
|
||||
import React from 'react'
|
||||
import Document, { Html, Head, Main, NextScript } from 'next/document'
|
||||
|
||||
export default class MyDocument extends Document {
|
||||
render() {
|
||||
return (
|
||||
<Html lang='en'>
|
||||
<Head />
|
||||
<Head>
|
||||
<link rel='shortcut icon' href='/favicon.ico' />
|
||||
|
||||
<link
|
||||
rel='apple-touch-icon'
|
||||
sizes='180x180'
|
||||
href='/apple-touch-icon.png'
|
||||
/>
|
||||
<link
|
||||
rel='icon'
|
||||
type='image/png'
|
||||
sizes='32x32'
|
||||
href='/favicon-32x32.png'
|
||||
/>
|
||||
<link
|
||||
rel='icon'
|
||||
type='image/png'
|
||||
sizes='16x16'
|
||||
href='/favicon-16x16.png'
|
||||
/>
|
||||
|
||||
<link rel='manifest' href='/manifest.json' />
|
||||
</Head>
|
||||
|
||||
<body>
|
||||
<Main />
|
||||
|
||||
@@ -1,60 +1,26 @@
|
||||
import React from 'react'
|
||||
import { isDemoMode, isDev } from 'lib/config'
|
||||
import { getSiteMaps } from 'lib/get-site-maps'
|
||||
import { domain } from 'lib/env'
|
||||
import { resolveNotionPage } from 'lib/resolve-notion-page'
|
||||
import { NotionPage } from 'components'
|
||||
|
||||
export const getStaticProps = async (context) => {
|
||||
const domain = context.params.domain as string
|
||||
const rawPageId = context.params.pageId as string
|
||||
const isDemo = isDemoMode(domain)
|
||||
|
||||
try {
|
||||
const props = await resolveNotionPage(domain, rawPageId)
|
||||
const props = await resolveNotionPage(domain)
|
||||
|
||||
return { props, unstable_revalidate: 10 }
|
||||
return { props, revalidate: 10 }
|
||||
} catch (err) {
|
||||
console.error('page error', domain, rawPageId, err)
|
||||
console.error('page error', domain, err)
|
||||
|
||||
return {
|
||||
props: {
|
||||
error: {
|
||||
statusCode: err.statusCode || 500,
|
||||
message: err.message
|
||||
},
|
||||
isDemo
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function getStaticPaths() {
|
||||
if (isDev) {
|
||||
return {
|
||||
paths: [],
|
||||
fallback: true
|
||||
}
|
||||
}
|
||||
|
||||
const siteMaps = await getSiteMaps()
|
||||
|
||||
const ret = {
|
||||
paths: siteMaps.flatMap((siteMap) =>
|
||||
siteMap.pageIds.map((pageId) => ({
|
||||
params: {
|
||||
domain: siteMap.site.domain,
|
||||
pageId
|
||||
}
|
||||
}))
|
||||
),
|
||||
// paths: [],
|
||||
fallback: true
|
||||
}
|
||||
|
||||
console.log(ret.paths)
|
||||
return ret
|
||||
}
|
||||
|
||||
export default function NotionDomainDynamicPage(props) {
|
||||
export default function NotionDomainPage(props) {
|
||||
return <NotionPage {...props} />
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user