---
import { getCollection, getEntry } from "astro:content";
import type { CollectionEntry } from "astro:content";
interface Props {
collectionName: CollectionEntry<"diaryMainPages">["slug"];
isOnTop?: boolean;
}
const { collectionName, isOnTop } = Astro.props;
const collectionTitle = (await getEntry("diaryMainPages", collectionName)).data.title;
const collection = (await getCollection(collectionName)).sort((a, b) => a.data.sorting - b.data.sorting);
const collectionBasePath = `/blog/${collectionName}`;
const currentIndex = collection.findIndex(entry => `${collectionBasePath}/${entry.slug}` === Astro.url.pathname);
const previousEntry = collection[currentIndex - 1];
const nextEntry = collection[currentIndex + 1];
const previousEntryLink = previousEntry ?
{show: true, href: `${collectionBasePath}/${previousEntry.slug}`, title: previousEntry.data.title} :
{show: currentIndex !== -1, href: collectionBasePath, title: collectionTitle};
const nextEntryLink = nextEntry ?
{href: `${collectionBasePath}/${nextEntry.slug}`, title: nextEntry.data.title} :
null ;
---