From 729d3ae6115ebbb403bca3c21eaedc18adf2c5c1 Mon Sep 17 00:00:00 2001 From: HangerThem Date: Tue, 4 Aug 2026 11:45:46 +0200 Subject: [PATCH] Better post navigation --- app/posts/[slug]/page.tsx | 29 +++++++++++++++++++++-------- lib/posts.tsx | 8 +++----- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/app/posts/[slug]/page.tsx b/app/posts/[slug]/page.tsx index 80a2f0c..9611625 100644 --- a/app/posts/[slug]/page.tsx +++ b/app/posts/[slug]/page.tsx @@ -4,7 +4,7 @@ import { ShareLinks } from '@/components/post/ShareLinks' import { TableOfContents } from '@/components/post/TableOfContents' import { getAllPostSlugs, getNextAndPreviousPosts, getPostBySlug } from '@/lib/posts' import { slugify } from '@/utils/slug' -import { Pencil, SendHorizonal } from 'lucide-react' +import { ArrowLeft, ArrowRight, Pencil, SendHorizonal } from 'lucide-react' import type { Metadata } from 'next' import Link from 'next/link' @@ -126,26 +126,39 @@ export default async function Post({ params }: { params: Promise<{ slug: string /> -
+
{previous ? ( - ← {previous.title} + + + Previous + + + {previous.title} + ) : ( -
+
)} + {next ? ( - {next.title} → + + Next + + + + {next.title} + ) : ( -
+
)}
diff --git a/lib/posts.tsx b/lib/posts.tsx index 8bfa22a..04746cb 100644 --- a/lib/posts.tsx +++ b/lib/posts.tsx @@ -56,8 +56,8 @@ export function getNextAndPreviousPosts(slug: string): { } { const posts = getAllPostsMeta() const index = posts.findIndex((post) => post.slug === slug) - const next = index < posts.length - 1 ? posts[index + 1] : null - const previous = index > 0 ? posts[index - 1] : null + const previous = index < posts.length - 1 ? posts[index + 1] : null + const next = index > 0 ? posts[index - 1] : null return { next, previous } } @@ -99,9 +99,7 @@ export async function getPostBySlug(slug: string, postDirectory: string = postsD img: ({ src, alt }: { src: string; alt: string }) => , a: ({ href, children }: { href: string; children: ReactNode }) => href?.startsWith('http') ? ( - - {children} - + {children} ) : ( {children} ),