From 650249e1a8fe7d6645bb712026930dd7e8906ef8 Mon Sep 17 00:00:00 2001 From: Dawid Rycerz Date: Fri, 30 Jan 2026 20:45:07 +0100 Subject: feat(blog): add next/previous post navigation scoped by category Navigate between posts within the same category (regular, microblog, archived). Newer post links left, older post links right. Includes i18n support for English and Polish. Co-Authored-By: Claude Opus 4.5 --- src/pages/posts/[...slug].astro | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/pages/posts') diff --git a/src/pages/posts/[...slug].astro b/src/pages/posts/[...slug].astro index 76e4f28..b66d911 100644 --- a/src/pages/posts/[...slug].astro +++ b/src/pages/posts/[...slug].astro @@ -1,24 +1,27 @@ --- import { render } from "astro:content"; import type { GetStaticPaths, InferGetStaticPropsType } from "astro"; -import { getAllPosts } from "@/data/post"; +import { getAllPosts, getPostNavigation } from "@/data/post"; import PostLayout from "@/layouts/BlogPost.astro"; // if you're using an adaptor in SSR mode, getStaticPaths wont work -> https://docs.astro.build/en/guides/routing/#modifying-the-slug-example-for-ssr export const getStaticPaths = (async () => { const blogEntries = await getAllPosts(true); // Include archived posts for direct access - return blogEntries.map((post) => ({ - params: { slug: post.id }, - props: { post }, - })); + return blogEntries.map((post) => { + const { prevPost, nextPost } = getPostNavigation(blogEntries, post); + return { + params: { slug: post.id }, + props: { post, prevPost, nextPost }, + }; + }); }) satisfies GetStaticPaths; type Props = InferGetStaticPropsType; -const { post } = Astro.props; +const { post, prevPost, nextPost } = Astro.props; const { Content } = await render(post); --- - + -- cgit v1.2.3