blog.z0x.ca/src/components/BlogCard.astro
2024-09-12 13:03:09 -07:00

86 lines
2.3 KiB
Text

---
import type { CollectionEntry } from 'astro:content'
import { formatDate, readingTime, parseAuthors } from '@lib/utils'
import { Image } from 'astro:assets'
import { Badge } from '@/components/ui/badge'
import { Separator } from '@/components/ui/separator'
import Link from './Link.astro'
type Props = {
entry: CollectionEntry<'blog'>
}
const { entry } = Astro.props as {
entry: CollectionEntry<'blog'>
}
const formattedDate = formatDate(entry.data.date)
const readTime = readingTime(entry.body)
const authors = await parseAuthors(entry.data.authors ?? [])
---
<div
class="not-prose rounded-xl border p-4 transition-colors duration-300 ease-in-out hover:bg-secondary/50"
>
<Link
href={`/${entry.collection}/${entry.slug}`}
class="flex flex-col gap-4 sm:flex-row"
>
{
entry.data.image && (
<div class="sm:flex-shrink-0">
<Image
src={entry.data.image}
alt={entry.data.title}
width={200}
height={200}
class="rounded-xl object-cover"
/>
</div>
)
}
<div class="flex-grow">
<h3 class="mb-1 text-lg font-semibold">
{entry.data.title}
</h3>
<p class="mb-2 text-sm text-muted-foreground">
{entry.data.description}
</p>
<div
class="mb-2 flex flex-wrap items-center gap-x-2 text-xs text-muted-foreground"
>
{
authors.length > 0 && (
<>
{authors.map((author) => (
<div class="flex items-center gap-x-1.5">
<Image
src={author.avatar}
alt={author.name}
width={18}
height={18}
class="rounded-full"
/>
<span>{author.name}</span>
</div>
))}
<Separator orientation="vertical" className="h-4" />
</>
)
}
<span>{formattedDate}</span>
<Separator orientation="vertical" className="h-4" />
<span>{readTime}</span>
</div>
{
entry.data.tags && (
<div class="flex flex-wrap gap-2">
{entry.data.tags.map((tag) => (
<Badge variant="secondary">{tag}</Badge>
))}
</div>
)
}
</div>
</Link>
</div>