{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "blog-index",
  "type": "registry:block",
  "title": "Blog Index",
  "description": "A year-grouped archive with category filters and a cursor-following preview.",
  "files": [
    {
      "path": "src/registry/blocks/blog/blog-index.tsx",
      "type": "registry:block",
      "content": "\"use client\";\n\nimport {\n  useEffect,\n  useId,\n  useMemo,\n  useRef,\n  useState,\n  type CSSProperties,\n  type ComponentProps,\n  type PointerEvent,\n} from \"react\";\nimport { useReducedMotion } from \"motion/react\";\nimport { cn } from \"@/lib/utils\";\n\nexport type BlogIndexEntry = {\n  title: string;\n  href: string;\n  category: string;\n  /** Display date inside its year group, e.g. \"02 Oct\". */\n  date: string;\n  /** Machine-readable date, e.g. \"2026-10-02\". The year groups come from this. */\n  dateTime: string;\n  /** Reading time in minutes. */\n  readingTime: number;\n  /** Shown as a pointer-following preview on desktop. */\n  image: { src: string; alt: string };\n};\n\nexport type BlogIndexProps = {\n  eyebrow?: string;\n  title?: string;\n  description?: string;\n  entries?: BlogIndexEntry[];\n  /** Ink for the active filter and the hovered row marker. */\n  accent?: string;\n} & ComponentProps<\"section\">;\n\nconst unsplash = (id: string) =>\n  `https://images.unsplash.com/${id}?w=480&h=360&q=80&auto=format&fit=crop`;\n\nconst DEFAULT_ENTRIES: BlogIndexEntry[] = [\n  {\n    title: \"We moved booking reminders to the night before. No-shows fell 31%\",\n    href: \"#\",\n    category: \"Field notes\",\n    date: \"02 Oct\",\n    dateTime: \"2026-10-02\",\n    readingTime: 9,\n    image: { src: unsplash(\"photo-1501785888041-af3ef285b470\"), alt: \"An alpine lake with a small boat\" },\n  },\n  {\n    title: \"Why the shops we love still hand-letter their opening hours\",\n    href: \"#\",\n    category: \"Owners\",\n    date: \"24 Sep\",\n    dateTime: \"2026-09-24\",\n    readingTime: 6,\n    image: { src: unsplash(\"photo-1472851294608-062f824d29cc\"), alt: \"An “Open” sign on a shop door\" },\n  },\n  {\n    title: \"Seasonal pricing is mostly a guess. Here is how to guess better\",\n    href: \"#\",\n    category: \"Operations\",\n    date: \"11 Sep\",\n    dateTime: \"2026-09-11\",\n    readingTime: 7,\n    image: { src: unsplash(\"photo-1507525428034-b723cf961d3e\"), alt: \"A beach at sunset\" },\n  },\n  {\n    title: \"Rebuilding the calendar view without breaking anyone’s bookmarks\",\n    href: \"#\",\n    category: \"Engineering\",\n    date: \"19 Aug\",\n    dateTime: \"2026-08-19\",\n    readingTime: 12,\n    image: { src: unsplash(\"photo-1551288049-bebda4e38f71\"), alt: \"An analytics dashboard on a laptop\" },\n  },\n  {\n    title: \"One person, forty rooms, and a front desk that closes at nine\",\n    href: \"#\",\n    category: \"Owners\",\n    date: \"03 Jul\",\n    dateTime: \"2026-07-03\",\n    readingTime: 8,\n    image: { src: unsplash(\"photo-1583847268964-b28dc8f51f92\"), alt: \"A cosy living room interior\" },\n  },\n  {\n    title: \"The case against a “Book now” button on every page\",\n    href: \"#\",\n    category: \"Design\",\n    date: \"28 Nov\",\n    dateTime: \"2025-11-28\",\n    readingTime: 5,\n    image: { src: unsplash(\"photo-1493809842364-78817add7ffb\"), alt: \"A bright living room with a blue sofa\" },\n  },\n  {\n    title: \"What a hostel in Zermatt taught us about overbooking on purpose\",\n    href: \"#\",\n    category: \"Field notes\",\n    date: \"14 Oct\",\n    dateTime: \"2025-10-14\",\n    readingTime: 10,\n    image: { src: unsplash(\"photo-1483728642387-6c3bdd6c93e5\"), alt: \"Snowy alpine peaks\" },\n  },\n  {\n    title: \"We deleted 40% of the settings screen. Nobody wrote in\",\n    href: \"#\",\n    category: \"Design\",\n    date: \"02 Jun\",\n    dateTime: \"2025-06-02\",\n    readingTime: 6,\n    image: { src: unsplash(\"photo-1485955900006-10f4d324d411\"), alt: \"A succulent in a mint pot on a white surface\" },\n  },\n  {\n    title: \"Moving nine million bookings to a new database on a Tuesday afternoon\",\n    href: \"#\",\n    category: \"Engineering\",\n    date: \"17 Mar\",\n    dateTime: \"2025-03-17\",\n    readingTime: 14,\n    image: { src: unsplash(\"photo-1480714378408-67cf0d13bc1b\"), alt: \"A city skyline\" },\n  },\n  {\n    title: \"Pricing the shoulder season: notes from sixty owners\",\n    href: \"#\",\n    category: \"Operations\",\n    date: \"21 Nov\",\n    dateTime: \"2024-11-21\",\n    readingTime: 9,\n    image: { src: unsplash(\"photo-1506905925346-21bda4d32df4\"), alt: \"Mountains above the clouds at dawn\" },\n  },\n  {\n    title: \"The guest who booked the same room for twenty-two summers\",\n    href: \"#\",\n    category: \"Owners\",\n    date: \"08 Aug\",\n    dateTime: \"2024-08-08\",\n    readingTime: 7,\n    image: { src: unsplash(\"photo-1441974231531-c6227db76b6e\"), alt: \"A sunlit forest path\" },\n  },\n  {\n    title: \"Why our invoices still fit on one printed page\",\n    href: \"#\",\n    category: \"Design\",\n    date: \"15 Feb\",\n    dateTime: \"2024-02-15\",\n    readingTime: 4,\n    image: { src: unsplash(\"photo-1448375240586-882707db888b\"), alt: \"Tall forest trees seen from below\" },\n  },\n];\n\nconst DEFAULTS = {\n  eyebrow: \"Saltbox Journal · Archive\",\n  title: \"Everything we’ve written down\",\n  description:\n    \"Three years of notes on running small guesthouses and shops: what worked, what didn’t, and the numbers behind both.\",\n  accent: \"#0A6EFF\",\n};\n\nconst PREVIEW_W = 240;\nconst PREVIEW_H = 180;\nconst OFFSET = 24;\n\nconst focusRing =\n  \"outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background\";\n\nexport function BlogIndex({\n  eyebrow = DEFAULTS.eyebrow,\n  title = DEFAULTS.title,\n  description = DEFAULTS.description,\n  entries = DEFAULT_ENTRIES,\n  accent = DEFAULTS.accent,\n  className,\n  style,\n  ...props\n}: BlogIndexProps) {\n  const headingId = useId();\n  const reduceMotion = useReducedMotion();\n  const [category, setCategory] = useState<string | null>(null);\n  const [active, setActive] = useState<string | null>(null);\n\n  const listRef = useRef<HTMLDivElement>(null);\n  const previewRef = useRef<HTMLDivElement>(null);\n  const frameRef = useRef(0);\n  const pointRef = useRef({ x: 0, y: 0 });\n\n  useEffect(() => () => cancelAnimationFrame(frameRef.current), []);\n\n  const categories = useMemo(\n    () => Array.from(new Set(entries.map((entry) => entry.category))),\n    [entries]\n  );\n\n  const groups = useMemo(() => {\n    const visible = category ? entries.filter((e) => e.category === category) : entries;\n    const byYear = new Map<string, BlogIndexEntry[]>();\n    for (const entry of visible) {\n      const year = entry.dateTime.slice(0, 4);\n      byYear.set(year, [...(byYear.get(year) ?? []), entry]);\n    }\n    return Array.from(byYear, ([year, items]) => ({ year, items })).sort((a, b) =>\n      b.year.localeCompare(a.year)\n    );\n  }, [entries, category]);\n\n  const visibleCount = groups.reduce((sum, group) => sum + group.items.length, 0);\n\n  const place = (x: number, y: number) => {\n    const preview = previewRef.current;\n    if (preview) preview.style.transform = `translate3d(${x}px, ${y}px, 0)`;\n  };\n\n  // Follow the pointer: write the transform straight to the DOM, once per frame.\n  const handlePointerMove = (event: PointerEvent<HTMLDivElement>) => {\n    if (event.pointerType !== \"mouse\" || reduceMotion || !listRef.current) return;\n    const rect = listRef.current.getBoundingClientRect();\n    pointRef.current = {\n      x: Math.min(event.clientX - rect.left + OFFSET, rect.width - PREVIEW_W),\n      y: event.clientY - rect.top - PREVIEW_H / 2,\n    };\n    if (frameRef.current) return;\n    frameRef.current = requestAnimationFrame(() => {\n      frameRef.current = 0;\n      place(pointRef.current.x, pointRef.current.y);\n    });\n  };\n\n  const handleRowEnter = (event: PointerEvent<HTMLAnchorElement>, key: string) => {\n    if (event.pointerType !== \"mouse\" || !listRef.current) return;\n    const list = listRef.current.getBoundingClientRect();\n    if (reduceMotion) {\n      // No following: pin the preview to the right edge, level with the row.\n      const row = event.currentTarget.getBoundingClientRect();\n      place(list.width - PREVIEW_W, row.top - list.top + row.height / 2 - PREVIEW_H / 2);\n    } else {\n      place(\n        Math.min(event.clientX - list.left + OFFSET, list.width - PREVIEW_W),\n        event.clientY - list.top - PREVIEW_H / 2\n      );\n    }\n    setActive(key);\n  };\n\n  return (\n    <section\n      data-slot=\"blog-index\"\n      aria-labelledby={headingId}\n      className={cn(\"w-full bg-background text-foreground\", className)}\n      style={{ \"--block-accent\": accent, ...style } as CSSProperties}\n      {...props}\n    >\n      <div className=\"mx-auto max-w-6xl px-6 py-20 md:py-28\">\n        <div className=\"grid gap-8 md:grid-cols-12\">\n          <div className=\"md:col-span-7\">\n            <p className=\"font-mono text-xs uppercase tracking-wider text-muted-foreground\">\n              {eyebrow}\n            </p>\n            <h2\n              id={headingId}\n              className=\"mt-5 text-4xl font-semibold leading-[1.02] tracking-[-0.03em] text-balance md:text-5xl\"\n            >\n              {title}\n            </h2>\n          </div>\n          <p className=\"max-w-sm text-sm leading-relaxed text-muted-foreground md:col-span-5 md:self-end md:justify-self-end\">\n            {description}\n          </p>\n        </div>\n\n        <div className=\"mt-12 flex flex-wrap items-baseline justify-between gap-x-8 gap-y-4 border-y py-4\">\n          <div role=\"group\" aria-label=\"Filter by category\" className=\"flex flex-wrap gap-x-5 gap-y-2\">\n            {[null, ...categories].map((item) => {\n              const pressed = category === item;\n              return (\n                <button\n                  key={item ?? \"all\"}\n                  type=\"button\"\n                  aria-pressed={pressed}\n                  onClick={() => setCategory(item)}\n                  className={cn(\n                    \"py-1 text-sm decoration-2 underline-offset-[6px] transition-colors\",\n                    pressed\n                      ? \"font-medium text-foreground underline decoration-[var(--block-accent)]\"\n                      : \"text-muted-foreground hover:text-foreground\",\n                    focusRing\n                  )}\n                >\n                  {item ?? \"All\"}\n                </button>\n              );\n            })}\n          </div>\n          <p aria-live=\"polite\" className=\"font-mono text-xs tabular-nums text-muted-foreground\">\n            {visibleCount} {visibleCount === 1 ? \"article\" : \"articles\"}\n          </p>\n        </div>\n\n        <div\n          ref={listRef}\n          className=\"relative\"\n          onPointerMove={handlePointerMove}\n          onPointerLeave={() => setActive(null)}\n        >\n          {groups.map(({ year, items }) => (\n            <div key={year} className=\"grid gap-x-10 border-b md:grid-cols-12\">\n              <h3 className=\"pt-8 pb-2 font-mono text-sm tabular-nums text-muted-foreground md:col-span-2 md:pb-8\">\n                {year}\n              </h3>\n              <ul className=\"divide-y md:col-span-10 md:py-2\">\n                {items.map((entry) => {\n                  const key = entry.dateTime + entry.title;\n                  return (\n                    <li key={key}>\n                      <a\n                        href={entry.href}\n                        onPointerEnter={(event) => handleRowEnter(event, key)}\n                        className={cn(\n                          \"group grid grid-cols-[1fr_auto] gap-x-6 gap-y-1 py-5 md:grid-cols-[4.5rem_1fr_7.5rem_4.5rem] md:items-baseline\",\n                          focusRing\n                        )}\n                      >\n                        <time\n                          dateTime={entry.dateTime}\n                          className=\"col-start-1 row-start-1 font-mono text-xs tabular-nums text-muted-foreground md:col-auto md:row-auto\"\n                        >\n                          {entry.date}\n                        </time>\n                        <span className=\"col-span-2 flex items-baseline gap-3 text-lg font-medium leading-snug tracking-[-0.015em] text-pretty md:col-span-1\">\n                          <span\n                            aria-hidden\n                            className={cn(\n                              \"hidden size-2 shrink-0 translate-y-[-0.15em] bg-[var(--block-accent)] transition-opacity md:inline-block\",\n                              active === key ? \"opacity-100\" : \"opacity-0\"\n                            )}\n                          />\n                          <span className=\"decoration-1 underline-offset-4 group-hover:underline\">\n                            {entry.title}\n                          </span>\n                        </span>\n                        <span className=\"col-start-2 row-start-1 text-right text-xs text-muted-foreground md:col-auto md:row-auto md:text-left md:text-sm\">\n                          {entry.category}\n                        </span>\n                        <span className=\"hidden text-right font-mono text-xs tabular-nums text-muted-foreground md:block\">\n                          {entry.readingTime} min\n                        </span>\n                      </a>\n                    </li>\n                  );\n                })}\n              </ul>\n            </div>\n          ))}\n\n          {visibleCount === 0 && (\n            <p className=\"border-b py-10 text-sm text-muted-foreground\">Nothing filed here yet.</p>\n          )}\n\n          {/* Pointer-following preview. Fine pointers only; touch taps just follow the link. */}\n          <div\n            ref={previewRef}\n            aria-hidden\n            className={cn(\n              \"pointer-events-none absolute top-0 left-0 z-10 hidden overflow-hidden border bg-muted transition-opacity duration-150 [@media(hover:hover)_and_(pointer:fine)]:md:block\",\n              active ? \"opacity-100\" : \"opacity-0\"\n            )}\n            style={{ width: PREVIEW_W, height: PREVIEW_H }}\n          >\n            {entries.map((entry) => {\n              const key = entry.dateTime + entry.title;\n              return (\n                // Plain <img> keeps the block portable outside Next.js.\n                // eslint-disable-next-line @next/next/no-img-element\n                <img\n                  key={key}\n                  src={entry.image.src}\n                  alt=\"\"\n                  width={PREVIEW_W}\n                  height={PREVIEW_H}\n                  loading=\"lazy\"\n                  className={cn(\n                    \"absolute inset-0 size-full object-cover\",\n                    active === key ? \"opacity-100\" : \"opacity-0\"\n                  )}\n                />\n              );\n            })}\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n"
    }
  ],
  "dependencies": [
    "motion"
  ]
}
