import Link from "next/link"; import Image from "next/image"; import { ImageIcon, User } from "lucide-react"; import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card"; import { getFeaturedImageUrl, type WpPost } from "@/lib/wp-api"; import { formatDateShamsi } from "@/lib/format-date"; function stripHtml(html: string): string { return html.replace(/<[^>]*>/g, "").trim(); } type BlogPostCardVariant = "default" | "tiny"; export function BlogPostCard({ post, variant = "default", }: { post: WpPost; variant?: BlogPostCardVariant; }) { const excerpt = stripHtml(post.excerpt.rendered) || stripHtml(post.content.rendered).slice(0, 160); const modifiedDate = post.modified ? formatDateShamsi(post.modified) : null; const authorName = post._embedded?.author?.[0]?.name ?? null; const thumbnailUrl = getFeaturedImageUrl(post, "full"); if (variant === "tiny") { return ( {thumbnailUrl ? (
) : (
)}

{post.title.rendered}

{authorName && ( {authorName} )} {modifiedDate && ( )}
); } return ( {thumbnailUrl ? (
) : (
)} {post.title.rendered}
{authorName && ( {authorName} )} {modifiedDate && ( )}

{excerpt}

); }