writing.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import Link from "next/link";
  2. import { FitList } from "./fit-list";
  3. import { Chevron } from "./ui";
  4. export type PostSummary = {
  5. id: string;
  6. title: string;
  7. createdAt: string | null;
  8. };
  9. const fmt = (iso: string | null) =>
  10. iso
  11. ? new Date(iso).toLocaleDateString("en-US", {
  12. month: "short",
  13. year: "numeric",
  14. timeZone: "UTC",
  15. })
  16. : "";
  17. export function WritingCard({ posts }: { posts: PostSummary[] }) {
  18. return (
  19. <div className="flex h-full flex-col p-5 sm:p-6">
  20. <div className="flex items-center justify-between">
  21. <p className="font-display text-[17px] font-semibold tracking-[-0.005em]">
  22. Writing
  23. </p>
  24. <Link
  25. className="inline-flex items-center gap-1 text-[13px] font-medium text-glacier-ink hover:underline hover:underline-offset-4"
  26. data-cursor="All posts"
  27. href="/blog"
  28. >
  29. All posts
  30. <Chevron />
  31. </Link>
  32. </div>
  33. {/* As many posts as the card has room for; the rows that show share out
  34. the spare height, so the list always ends at the card's inset. Rows
  35. never shrink, so FitList can see which ones overflow. */}
  36. <FitList className="mt-2 flex min-h-0 flex-1 flex-col">
  37. {posts.slice(0, 10).map((p) => (
  38. <li
  39. key={p.id}
  40. className="flex flex-[1_0_auto] flex-col border-t border-line first:border-t-0"
  41. >
  42. <Link
  43. className="group flex flex-1 items-center py-2.5"
  44. data-cursor="Read"
  45. href={`/blog/${p.id}`}
  46. prefetch={false}
  47. >
  48. <span className="flex w-full min-w-0 items-baseline justify-between gap-4">
  49. <span className="truncate text-[15px] font-medium transition-colors group-hover:text-glacier">
  50. {p.title}
  51. </span>
  52. <time
  53. className="shrink-0 text-[13px] text-muted tabular-nums"
  54. dateTime={p.createdAt ?? undefined}
  55. >
  56. {fmt(p.createdAt)}
  57. </time>
  58. </span>
  59. </Link>
  60. </li>
  61. ))}
  62. {posts.length === 0 && (
  63. <li className="py-3 text-[14px] text-ink-2">
  64. <Link className="hover:text-glacier" href="/blog">
  65. Read the blog →
  66. </Link>
  67. </li>
  68. )}
  69. </FitList>
  70. </div>
  71. );
  72. }