This commit is contained in:
2026-01-17 01:22:01 +01:00
parent c258e5c695
commit c12b32ed5e
103 changed files with 12912 additions and 214 deletions

View File

@@ -56,3 +56,20 @@ export async function getAllPosts(locale: string): Promise<PostMdx[]> {
return posts;
}
export async function getAdjacentPosts(slug: string, locale: string): Promise<{ prev: PostMdx | null; next: PostMdx | null }> {
const posts = await getAllPosts(locale);
const currentIndex = posts.findIndex(post => post.slug === slug);
if (currentIndex === -1) {
return { prev: null, next: null };
}
// Posts are sorted by date descending (newest first)
// So "next" post (newer) is at index - 1
// And "previous" post (older) is at index + 1
const next = currentIndex > 0 ? posts[currentIndex - 1] : null;
const prev = currentIndex < posts.length - 1 ? posts[currentIndex + 1] : null;
return { prev, next };
}