writing.tsx 2.6 KB

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