Skip to content

Commit

Permalink
Fix. 修复只有一篇文章时的建议错误问题
Browse files Browse the repository at this point in the history
Co-authored-by: PaloMiku <palomiku@outlook.com>
  • Loading branch information
RavelloH and PaloMiku authored Oct 31, 2024
1 parent a966a1b commit ed27eb9
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions src/components/PostSuggeston.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
<div id='more-articles'>
Expand Down

0 comments on commit ed27eb9

Please sign in to comment.