封装 allPages

This commit is contained in:
tlyong1992
2022-05-18 13:46:08 +08:00
parent b453df8d5d
commit 598d8d0b5b
4 changed files with 29 additions and 83 deletions

View File

@@ -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,