From 59c2224f717b449b1bf29ec66314cee37d335bf1 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Tue, 18 Jan 2022 16:28:01 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A4=BA=E4=BE=8B=E6=96=87=E7=AB=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/article/[slug].js | 12 ++++++------ themes/NEXT/components/BlogAround.js | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pages/article/[slug].js b/pages/article/[slug].js index e8ac532d..7903994f 100644 --- a/pages/article/[slug].js +++ b/pages/article/[slug].js @@ -13,7 +13,7 @@ const Slug = (props) => { if (!props.post) { return } - return + return } export async function getStaticPaths () { @@ -45,10 +45,10 @@ export async function getStaticProps ({ params: { slug } }) { post.blockMap = await getPostBlocks(post.id, 'slug') - // 上一篇、下一篇文章关联 - const index = allPosts.indexOf(post) - const prev = allPosts.slice(index - 1, index)[0] ?? allPosts.slice(-1)[0] - const next = allPosts.slice(index + 1, index + 2)[0] ?? allPosts[0] + const posts = allPosts.filter(post => post?.type?.[0] === 'Post') + const index = posts.indexOf(post) + const prev = posts.slice(index - 1, index)[0] ?? posts.slice(-1)[0] + const next = posts.slice(index + 1, index + 2)[0] ?? posts[0] const recommendPosts = getRecommendPost(post, allPosts) @@ -80,7 +80,7 @@ function getRecommendPost (post, allPosts, count = 5) { if (post.tags && post.tags.length) { const currentTag = post.tags[0] filteredPosts = filteredPosts.filter( - p => p && p.tags && p.tags.includes(currentTag) && p.slug !== post.slug + p => p && p.tags && p.tags.includes(currentTag) && p.slug !== post.slug && p.type === 'post' ) } shuffleSort(filteredPosts) diff --git a/themes/NEXT/components/BlogAround.js b/themes/NEXT/components/BlogAround.js index 96f2a504..f69d4d78 100644 --- a/themes/NEXT/components/BlogAround.js +++ b/themes/NEXT/components/BlogAround.js @@ -12,15 +12,15 @@ export default function BlogAround ({ prev, next }) { return <> } return
- + {prev && {prev.title} - - + } + {next && {next.title} - + }
}