- Updated Astro core package and related integrations to latest versions - Added environment variable configuration in astro.config.mjs - Removed deprecated migration plan and favicon.svg files - Updated Search component to use onCleanup for proper effect cleanup - Updated Appwrite service integration and configuration - Removed old migration documentation and scripts
97 lines
4.3 KiB
Plaintext
97 lines
4.3 KiB
Plaintext
---
|
|
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]
|
|
}
|
|
}
|
|
---
|
|
|
|
<div>
|
|
<article class="text-spaghetti-brown/80 dark:text-spaghetti-cream" set:html={content} />
|
|
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
|
{prevEntry && (
|
|
<a href={`/${collection}/${prevEntry.$id}`} class="group p-4 gap-3 flex items-center border rounded-lg hover:bg-black/5 hover:dark:bg-spaghetti-cream/10 border-black/15 dark:border-spaghetti-cream/20 blend">
|
|
<div class="order-2 w-full h-full group-hover:text-spaghetti-brown/80 group-hover:dark:text-spaghetti-cream blend">
|
|
<div class="flex flex-wrap gap-2">
|
|
<div class="text-sm uppercase">
|
|
Prev
|
|
</div>
|
|
</div>
|
|
<div class="font-semibold mt-3 text-spaghetti-brown/80 dark:text-spaghetti-cream">
|
|
{prevEntry.title}
|
|
</div>
|
|
</div>
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" class="order-1 stroke-current group-hover:stroke-black group-hover:dark:stroke-white rotate-180">
|
|
<line x1="5" y1="12" x2="19" y2="12" class="scale-x-0 group-hover:scale-x-100 translate-x-4 group-hover:translate-x-1 transition-all duration-300 ease-in-out" />
|
|
<polyline points="12 5 19 12 12 19" class="translate-x-0 group-hover:translate-x-1 transition-all duration-300 ease-in-out" />
|
|
</svg>
|
|
</a>
|
|
)}
|
|
{nextEntry && (
|
|
<a href={`/${collection}/${nextEntry.$id}`} class="group p-4 gap-3 flex items-center border rounded-lg hover:bg-black/5 hover:dark:bg-spaghetti-cream/10 border-black/15 dark:border-spaghetti-cream/20 transition-colors duration-300 ease-in-out">
|
|
<div class="w-full h-full text-right group-hover:text-spaghetti-brown/80 group-hover:dark:text-spaghetti-cream blend">
|
|
<div class="text-sm uppercase">
|
|
Next
|
|
</div>
|
|
<div class="font-semibold mt-3 text-spaghetti-brown/80 dark:text-spaghetti-cream">
|
|
{nextEntry.title}
|
|
</div>
|
|
</div>
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" class="stroke-current group-hover:stroke-black group-hover:dark:stroke-white">
|
|
<line x1="5" y1="12" x2="19" y2="12" class="scale-x-0 group-hover:scale-x-100 translate-x-4 group-hover:translate-x-1 transition-all duration-300 ease-in-out" />
|
|
<polyline points="12 5 19 12 12 19" class="translate-x-0 group-hover:translate-x-1 transition-all duration-300 ease-in-out" />
|
|
</svg>
|
|
</a>
|
|
)}
|
|
{!prevEntry && !nextEntry && (
|
|
<div class="col-span-2 text-center py-8 text-gray-500">
|
|
No adjacent articles available
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|