--- import Blog from '@/layouts/Blog.astro'; import type { GetStaticPaths } from 'astro'; import { getCollection, render } from 'astro:content'; export const getStaticPaths = (async () => { const blog = await getCollection("blog"); return blog.map(entry => ({ params: { id: entry.id }, props: { entry }, })); }) satisfies GetStaticPaths; const { entry } = Astro.props; const { Content } = await render(entry); const blog = await getCollection("blog"); blog.sort((a, b) => b.data.pubDate!.valueOf() - a.data.pubDate!.valueOf()); const current = blog.findIndex(entry => entry.id === Astro.params.id); const previous = current + 1 === blog.length ? undefined : blog[current + 1]; const next = current === 0 ? undefined : blog[current - 1]; --- {(previous || next) && (
{previous && ( )} {next && ( )}
)}