blog-list.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import Link from "next/link";
  2. import { Cover } from "@/components/blog/cover";
  3. import { Eyebrow } from "@/components/cards/ui";
  4. import type { Blog } from "@/types/blog";
  5. type Post = Blog & { imageUrl: string | undefined };
  6. const fmt = (d: Date | null) =>
  7. d
  8. ? d.toLocaleDateString("en-US", {
  9. month: "short",
  10. day: "numeric",
  11. year: "numeric",
  12. timeZone: "UTC",
  13. })
  14. : "";
  15. export function BlogList({ blogPosts }: { blogPosts: Post[] }) {
  16. return (
  17. <div className="pb-6">
  18. <header className="mb-8 flex flex-col items-start gap-3 pt-2 sm:mb-10">
  19. <Eyebrow>Writing · {blogPosts.length} posts</Eyebrow>
  20. <h1 className="font-display text-[clamp(2.3rem,5.2vw,3.6rem)] leading-[1.02] font-semibold tracking-[-0.02em]">
  21. Notes from the trail &amp; the terminal.
  22. </h1>
  23. <p className="max-w-[56ch] text-[15px] text-ink-2">
  24. Things I&apos;ve built, broken, and learned along the way.
  25. </p>
  26. </header>
  27. <div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3">
  28. {blogPosts.map(({ id, title, imageUrl, createdAt, description }, i) => (
  29. <Link
  30. key={id}
  31. className="card group flex flex-col transition-[translate,box-shadow] duration-500 hover:-translate-y-1"
  32. data-cursor="Read"
  33. href={`/blog/${id}`}
  34. >
  35. <div className="relative aspect-[16/9] overflow-hidden bg-card-2">
  36. <Cover index={i} src={imageUrl} title={title} />
  37. </div>
  38. <div className="flex flex-1 flex-col gap-2 p-5">
  39. <h2 className="text-[1.05rem] leading-snug font-semibold tracking-tight transition-colors group-hover:text-glacier">
  40. {title}
  41. </h2>
  42. {description && (
  43. <p className="line-clamp-2 text-[13.5px] text-ink-2">
  44. {description}
  45. </p>
  46. )}
  47. {createdAt && (
  48. <time
  49. className="mt-auto pt-2 text-[13px] text-muted"
  50. dateTime={createdAt.toISOString()}
  51. >
  52. {fmt(createdAt)}
  53. </time>
  54. )}
  55. </div>
  56. </Link>
  57. ))}
  58. </div>
  59. </div>
  60. );
  61. }