Skip to content

Commit b07ee5c

Browse files
authored
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.
1 parent b3680c5 commit b07ee5c

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/layouts/PostDetails.astro

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,13 @@ const layoutProps = {
6969
7070
/* ========== Prev/Next Posts ========== */
7171
72-
const allPosts = posts.map(({ data: { title }, id }) => ({
73-
slug: id,
72+
const allPosts = posts.map(({ data: { title }, id, filePath }) => ({
73+
id,
7474
title,
75+
filePath,
7576
}));
7677
77-
const currentPostIndex = allPosts.findIndex(a => a.slug === post.id);
78+
const currentPostIndex = allPosts.findIndex(a => a.id === post.id);
7879
7980
const prevPost = currentPostIndex !== 0 ? allPosts[currentPostIndex - 1] : null;
8081
const nextPost =
@@ -125,7 +126,7 @@ const nextPost =
125126
{
126127
prevPost && (
127128
<a
128-
href={`/posts/${prevPost.slug}`}
129+
href={getPath(prevPost.id, prevPost.filePath)}
129130
class="flex w-full gap-1 hover:opacity-75"
130131
>
131132
<IconChevronLeft class="inline-block flex-none" />
@@ -139,7 +140,7 @@ const nextPost =
139140
{
140141
nextPost && (
141142
<a
142-
href={`/posts/${nextPost.slug}`}
143+
href={getPath(nextPost.id, nextPost.filePath)}
143144
class="flex w-full justify-end gap-1 text-right hover:opacity-75 sm:col-start-2"
144145
>
145146
<div>

0 commit comments

Comments
 (0)