30 lines
973 B
Plaintext
30 lines
973 B
Plaintext
---
|
|
import { getCollection } from 'astro:content';
|
|
import BaseLayout from '@layouts/BaseLayout.astro';
|
|
import Post from '@components/Post.astro';
|
|
|
|
export async function getStaticPaths() {
|
|
const entries = await getCollection('posts');
|
|
// unlike `/index` and `/posts`, we want to sort ascending by date here
|
|
entries.sort((a, b) => a.data.date.getTime() - b.data.date.getTime());
|
|
|
|
// for each route, the page gets passed the entry itself, plus the previous and next slugs
|
|
// (if any), so that it can render links to them
|
|
return entries.map((entry, idx) => {
|
|
const prevSlug = entries[idx - 1]?.id || null;
|
|
const nextSlug = entries[idx + 1]?.id || null;
|
|
return {
|
|
params: { slug: entry.id },
|
|
props: { entry, prevSlug, nextSlug },
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
const { entry, prevSlug, nextSlug } = Astro.props;
|
|
---
|
|
|
|
<BaseLayout pageTitle={entry.data.title}>
|
|
<Post {entry} {prevSlug} {nextSlug} />
|
|
</BaseLayout>
|