From b59f86d85259083c8eed5288eb301703ffef1f1c Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Thu, 8 Dec 2022 12:18:04 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=96=E8=AF=91=E9=94=99?= =?UTF-8?q?=E8=AF=AF=EF=BC=8C=E4=BF=AE=E5=A4=8D=E5=A4=96=E9=93=BE=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/notion/getPageProperties.js | 2 +- pages/[...slug].js | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/notion/getPageProperties.js b/lib/notion/getPageProperties.js index 7c1cdb4f..f4ee3282 100644 --- a/lib/notion/getPageProperties.js +++ b/lib/notion/getPageProperties.js @@ -78,7 +78,7 @@ export default async function getPageProperties(id, block, schema, authToken, ta // 开启伪静态路径 if (BLOG.PSEUDO_STATIC) { - if (!properties.slug.endsWith('.html')) { + if (!properties?.slug?.endsWith('.html') && !properties?.slug?.startsWith('http')) { properties.slug += '.html' } } diff --git a/pages/[...slug].js b/pages/[...slug].js index b16fff72..c790f211 100644 --- a/pages/[...slug].js +++ b/pages/[...slug].js @@ -124,14 +124,17 @@ export async function getStaticProps({ params: { slug } }) { } const allPosts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published') - const index = allPosts.indexOf(props.post) - props.prev = allPosts.slice(index - 1, index)[0] ?? allPosts.slice(-1)[0] - props.next = allPosts.slice(index + 1, index + 2)[0] ?? allPosts[0] - props.recommendPosts = getRecommendPost( - props.post, - allPosts, - BLOG.POST_RECOMMEND_COUNT - ) + if (allPosts && allPosts.length > 0) { + const index = allPosts.indexOf(props.post) + props.prev = allPosts.slice(index - 1, index)[0] ?? allPosts.slice(-1)[0] + props.next = allPosts.slice(index + 1, index + 2)[0] ?? allPosts[0] + props.recommendPosts = getRecommendPost(props.post, allPosts, BLOG.POST_RECOMMEND_COUNT) + } else { + props.prev = null + props.next = null + props.recommendPosts = [] + } + delete props.allPages return { props,