--- import type { BlogPost, Project } from "@lib/appwrite-service" import { formatDate, readingTime } from "@lib/utils" import { getBlogPosts, getProjects } from "@lib/appwrite-service" type Props = { entry: BlogPost | Project | any } const { entry } = Astro.props const collection = entry.$collectionId === process.env.VITE_APPWRITE_BLOG_COLLECTION_ID ? 'blog' : 'projects' // Get the content from the entry const content = entry.contentHtml // Fetch all documents for navigation let prevEntry = null let nextEntry = null if (collection === "blog") { const blogPosts = await getBlogPosts() // Sort by date descending to get newest first const sortedPosts = blogPosts.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()) // Find current post index const currentIndex = sortedPosts.findIndex(post => post.$id === entry.$id) if (currentIndex > 0) { prevEntry = sortedPosts[currentIndex - 1] } if (currentIndex < sortedPosts.length - 1) { nextEntry = sortedPosts[currentIndex + 1] } } else if (collection === "projects") { const projects = await getProjects() // Sort by date descending to get newest first const sortedProjects = projects.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()) // Find current project index const currentIndex = sortedProjects.findIndex(project => project.$id === entry.$id) if (currentIndex > 0) { prevEntry = sortedProjects[currentIndex - 1] } if (currentIndex < sortedProjects.length - 1) { nextEntry = sortedProjects[currentIndex + 1] } } ---
{prevEntry && (
Prev
{prevEntry.title}
)} {nextEntry && (
Next
{nextEntry.title}
)} {!prevEntry && !nextEntry && (
No adjacent articles available
)}