mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-29 15:10:06 +00:00
封装 allPages
This commit is contained in:
@@ -80,12 +80,10 @@ export async function getStaticPaths() {
|
||||
}
|
||||
|
||||
const from = 'slug-paths'
|
||||
const { allPosts } = await getGlobalNotionData({ from, pageType: ['Page'] })
|
||||
const filterPosts =
|
||||
allPosts?.filter(e => e?.slug?.indexOf('http') !== 0) || []
|
||||
const { allPages } = await getGlobalNotionData({ from, pageType: ['Page'] })
|
||||
|
||||
return {
|
||||
paths: filterPosts.map(row => ({ params: { slug: row.slug } })),
|
||||
paths: allPages.map(row => ({ params: { slug: row.slug } })),
|
||||
fallback: true
|
||||
}
|
||||
}
|
||||
@@ -93,19 +91,19 @@ export async function getStaticPaths() {
|
||||
export async function getStaticProps({ params: { slug } }) {
|
||||
const from = `slug-props-${slug}`
|
||||
const props = await getGlobalNotionData({ from, pageType: ['Page'] })
|
||||
const { allPosts } = props
|
||||
const post = allPosts.find(p => p.slug === slug)
|
||||
if (!post) {
|
||||
const { allPages } = props
|
||||
const page = allPages?.find(p => p.slug === slug)
|
||||
if (!page) {
|
||||
return { props: {}, revalidate: 1 }
|
||||
}
|
||||
|
||||
try {
|
||||
post.blockMap = await getPostBlocks(post.id, 'slug')
|
||||
page.blockMap = await getPostBlocks(page.id, 'slug')
|
||||
} catch (error) {
|
||||
console.error('获取文章详情失败', error)
|
||||
}
|
||||
|
||||
props.post = post
|
||||
props.post = page
|
||||
|
||||
return {
|
||||
props,
|
||||
|
||||
Reference in New Issue
Block a user