mirror of
https://github.com/ChenQihan666/MyBlog-Next.git
synced 2026-08-14 07:33:07 +08:00
fix: replace broken prev/next links with correct paths (#533)
Nested blog post URLs in the prev/next links were not updated properly, which resulted in 404 error pages. This commit updates the outdated URLs to the correct paths.
This commit is contained in:
@@ -69,12 +69,13 @@ const layoutProps = {
|
||||
|
||||
/* ========== Prev/Next Posts ========== */
|
||||
|
||||
const allPosts = posts.map(({ data: { title }, id }) => ({
|
||||
slug: id,
|
||||
const allPosts = posts.map(({ data: { title }, id, filePath }) => ({
|
||||
id,
|
||||
title,
|
||||
filePath,
|
||||
}));
|
||||
|
||||
const currentPostIndex = allPosts.findIndex(a => a.slug === post.id);
|
||||
const currentPostIndex = allPosts.findIndex(a => a.id === post.id);
|
||||
|
||||
const prevPost = currentPostIndex !== 0 ? allPosts[currentPostIndex - 1] : null;
|
||||
const nextPost =
|
||||
@@ -125,7 +126,7 @@ const nextPost =
|
||||
{
|
||||
prevPost && (
|
||||
<a
|
||||
href={`/posts/${prevPost.slug}`}
|
||||
href={getPath(prevPost.id, prevPost.filePath)}
|
||||
class="flex w-full gap-1 hover:opacity-75"
|
||||
>
|
||||
<IconChevronLeft class="inline-block flex-none" />
|
||||
@@ -139,7 +140,7 @@ const nextPost =
|
||||
{
|
||||
nextPost && (
|
||||
<a
|
||||
href={`/posts/${nextPost.slug}`}
|
||||
href={getPath(nextPost.id, nextPost.filePath)}
|
||||
class="flex w-full justify-end gap-1 text-right hover:opacity-75 sm:col-start-2"
|
||||
>
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user