Skip to content

Commit 9d68bf7

Browse files
satnaingmiyayaLora
authored andcommitted
fix: replace broken prev/next links with correct paths (satnaing#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. (cherry picked from commit b07ee5c)
1 parent 280d519 commit 9d68bf7

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 =
@@ -232,7 +233,7 @@ const nextPost =
232233
{
233234
prevPost && (
234235
<a
235-
href={`/posts/${prevPost.slug}`}
236+
href={getPath(prevPost.id, prevPost.filePath)}
236237
class="flex w-full gap-1 hover:-top-0.5 hover:text-accent/85 focus-visible:p-1"
237238
>
238239
<IconChevronLeft class="inline-block size-12 flex-none justify-center" />
@@ -246,7 +247,7 @@ const nextPost =
246247
{
247248
nextPost && (
248249
<a
249-
href={`/posts/${nextPost.slug}`}
250+
href={getPath(nextPost.id, nextPost.filePath)}
250251
class="flex w-full justify-end gap-1 text-right hover:-top-0.5 hover:text-accent/85 focus-visible:p-1 sm:col-start-2"
251252
>
252253
<div>

0 commit comments

Comments
 (0)