From ed27eb941fcfb54a04b3677181a7a4a82ed8e803 Mon Sep 17 00:00:00 2001 From: RavelloH Date: Thu, 31 Oct 2024 12:57:08 +0800 Subject: [PATCH] =?UTF-8?q?Fix.=20=E4=BF=AE=E5=A4=8D=E5=8F=AA=E6=9C=89?= =?UTF-8?q?=E4=B8=80=E7=AF=87=E6=96=87=E7=AB=A0=E6=97=B6=E7=9A=84=E5=BB=BA?= =?UTF-8?q?=E8=AE=AE=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: PaloMiku --- src/components/PostSuggeston.jsx | 43 ++++++++++++++++---------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/components/PostSuggeston.jsx b/src/components/PostSuggeston.jsx index 1e0a85a..cb0e3e8 100644 --- a/src/components/PostSuggeston.jsx +++ b/src/components/PostSuggeston.jsx @@ -14,28 +14,27 @@ await prisma.$disconnect(); let previousArticlesUrl, nextArticlesUrl, previousArticlesTitle, nextArticlesTitle; -export default function PostSuggestion(parmas) { - for (let i = 0; i < posts.length; i++) { - if (posts[i].name == parmas.name) { - if (i == 0) { - previousArticlesUrl = null; - nextArticlesUrl = posts[i + 1].name; - previousArticlesTitle = null; - nextArticlesTitle = posts[i + 1].title; - } else if (i == posts.length - 1) { - previousArticlesUrl = posts[i - 1].name; - nextArticlesUrl = null; - previousArticlesTitle = posts[i - 1].title; - nextArticlesTitle = null; - } else { - previousArticlesUrl = posts[i - 1].name; - nextArticlesUrl = posts[i + 1].name; - previousArticlesTitle = posts[i - 1].title; - nextArticlesTitle = posts[i + 1].title; - } - } - } - +export default function PostSuggestion(params) { +    for (let i = 0; i < posts.length; i++) { +        if (posts[i].name == params.name) { +            if (i == 0) { +                previousArticlesUrl = null; +                nextArticlesUrl = posts[i + 1] ? posts[i + 1].name : null; +                previousArticlesTitle = null; +                nextArticlesTitle = posts[i + 1] ? posts[i + 1].title : null; +            } else if (i == posts.length - 1) { +                previousArticlesUrl = posts[i - 1] ? posts[i - 1].name : null; +                nextArticlesUrl = null; +                previousArticlesTitle = posts[i - 1] ? posts[i - 1].title : null; +                nextArticlesTitle = null; +            } else { +                previousArticlesUrl = posts[i - 1] ? posts[i - 1].name : null; +                nextArticlesUrl = posts[i + 1] ? posts[i + 1].name : null; +                previousArticlesTitle = posts[i - 1] ? posts[i - 1].title : null; +                nextArticlesTitle = posts[i + 1] ? posts[i + 1].title : null; +            } +        } +    } return ( <>