Add storyline navigation rail for posts

This commit is contained in:
2025-11-18 16:45:46 +08:00
parent 4b3329d66f
commit 96ebca37d6
4 changed files with 206 additions and 1 deletions

View File

@@ -87,3 +87,18 @@ export function getRelatedPosts(target: Post, limit = 3): Post[] {
return [...scored, ...fallback.slice(0, limit - scored.length)].slice(0, limit);
}
export function getPostNeighbors(target: Post): {
newer?: Post;
older?: Post;
} {
const sorted = getAllPostsSorted();
const index = sorted.findIndex((post) => post._id === target._id);
if (index === -1) return {};
return {
newer: index > 0 ? sorted[index - 1] : undefined,
older: index < sorted.length - 1 ? sorted[index + 1] : undefined
};
}