writing.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import Link from "next/link";
  2. import { Chevron } from "./ui";
  3. export type PostSummary = {
  4. id: string;
  5. title: string;
  6. createdAt: string | null;
  7. };
  8. const fmt = (iso: string | null) =>
  9. iso
  10. ? new Date(iso).toLocaleDateString("en-US", {
  11. month: "short",
  12. year: "numeric",
  13. timeZone: "UTC",
  14. })
  15. : "";
  16. export function WritingCard({ posts }: { posts: PostSummary[] }) {
  17. return (
  18. <div className="flex h-full flex-col p-5 sm:p-6">
  19. <div className="flex items-center justify-between">
  20. <p className="font-display text-[17px] font-semibold tracking-[-0.005em]">
  21. Writing
  22. </p>
  23. <Link
  24. className="inline-flex items-center gap-1 text-[13px] font-medium text-glacier-ink hover:underline hover:underline-offset-4"
  25. data-cursor="All posts"
  26. href="/blog"
  27. >
  28. All posts
  29. <Chevron />
  30. </Link>
  31. </div>
  32. <ul className="mt-2 flex flex-1 flex-col justify-start divide-y divide-line sm:justify-center">
  33. {posts.slice(0, 5).map((p, i) => (
  34. <li key={p.id} className={i >= 3 ? "sm:hidden" : undefined}>
  35. <Link
  36. className="group flex items-baseline justify-between gap-4 py-2.5"
  37. data-cursor="Read"
  38. href={`/blog/${p.id}`}
  39. prefetch={false}
  40. >
  41. <span className="truncate text-[15px] font-medium transition-colors group-hover:text-glacier">
  42. {p.title}
  43. </span>
  44. <time
  45. className="shrink-0 text-[13px] text-muted tabular-nums"
  46. dateTime={p.createdAt ?? undefined}
  47. >
  48. {fmt(p.createdAt)}
  49. </time>
  50. </Link>
  51. </li>
  52. ))}
  53. {posts.length === 0 && (
  54. <li className="py-3 text-[14px] text-ink-2">
  55. <Link className="hover:text-glacier" href="/blog">
  56. Read the blog →
  57. </Link>
  58. </li>
  59. )}
  60. </ul>
  61. </div>
  62. );
  63. }