2024-12-26 15:02:43 +00:00
|
|
|
---
|
2025-01-19 13:10:44 +00:00
|
|
|
import Button from "./Button.astro";
|
2024-12-26 15:02:43 +00:00
|
|
|
import { type CollectionEntry, getCollection } from "astro:content";
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
entry: CollectionEntry<"posts"> | CollectionEntry<"projects">;
|
|
|
|
};
|
|
|
|
|
|
|
|
const { entry } = Astro.props;
|
|
|
|
const { collection } = entry;
|
|
|
|
|
|
|
|
const items = (await getCollection(collection))
|
|
|
|
.filter((post) => !post.data.draft)
|
|
|
|
.sort((a, b) => b.data.date.getTime() - a.data.date.getTime());
|
|
|
|
const index = items.findIndex((x) => x.slug === entry.slug);
|
|
|
|
const prev = items[(index - 1 + items.length) % items.length];
|
|
|
|
const next = items[(index + 1) % items.length];
|
|
|
|
---
|
|
|
|
|
2025-01-05 18:49:48 +00:00
|
|
|
{
|
|
|
|
items.length > 1 ? (
|
|
|
|
<div class="mx-auto mt-8 flex max-w-prose justify-between gap-4 md:gap-0">
|
2025-01-19 13:10:44 +00:00
|
|
|
<div class="group flex w-fit flex-row items-center justify-between">
|
|
|
|
<Button
|
2025-01-05 18:49:48 +00:00
|
|
|
href={`/${prev.collection}/${prev.slug}`}
|
2025-01-19 13:10:44 +00:00
|
|
|
link={`Previous: ${prev.data.title}`}
|
|
|
|
/>
|
2025-01-05 18:49:48 +00:00
|
|
|
</div>
|
2025-01-19 13:10:44 +00:00
|
|
|
<div class="group flex w-fit flex-row items-center justify-between self-end">
|
|
|
|
<Button
|
2025-01-05 18:49:48 +00:00
|
|
|
href={`/${next.collection}/${next.slug}`}
|
2025-01-19 13:10:44 +00:00
|
|
|
link={`Next: ${next.data.title}`}
|
|
|
|
/>
|
2025-01-05 18:49:48 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
) : null
|
|
|
|
}
|