/* ═══════════════════════════════════════════════════════════════ BLOG DATA GET /blog/:id and GET /community-blog, as routes/blog.js shapes them. The section's community posts arrive as featured cards, so FeaturedCards.tsx draws them unchanged. ═══════════════════════════════════════════════════════════════ */ import { detailPath } from './hrefs.ts' import { useRecord, type Resource } from './useRecord.ts' import type { ContentBlock } from './useContent.ts' import type { FeaturedCard } from './useFrontPage.ts' export type BlogAuthor = { id: string name: string pronouns?: string | null tagline?: string | null photo?: string | null } export type BlogPostRecord = { id: string title: string excerpt?: string | null cover_image?: string | null cover_alt?: string | null /** List the post's headings beside it. */ show_contents?: boolean published_on?: string | null tags: string[] authors: BlogAuthor[] guest: { name: string; photo?: string | null } | null blocks: ContentBlock[] is_listed: boolean } /** A post on the Community page's section. `id` is null on a guest. */ export type BlogPostSummary = { id: string title: string excerpt?: string | null cover_image?: string | null published_on?: string | null tags: string[] authors: Array<{ id: string | null; name: string }> } export type CommunityBlog = { internal: { title?: string | null; posts: BlogPostSummary[] } external: { title?: string | null url?: string | null label?: string | null cards: FeaturedCard[] } } export const useBlogPost = (id?: string | null): Resource => useRecord(detailPath('/blog', id), 'post') export const useCommunityBlog = (): Resource => useRecord('/community-blog', 'community_blog') /** '2026-09-01' → 'September 1, 2026'. Parsed as a local date, so * it can't slip a day in a timezone west of UTC. */ export function postDate(value?: string | null): string | null { const match = value?.match(/^(\d{4})-(\d{2})-(\d{2})/) if (!match) return null const date = new Date(Number(match[1]), Number(match[2]) - 1, Number(match[3])) return date.toLocaleDateString(undefined, { year: 'numeric', month: 'long', day: 'numeric' }) }