Admin → Blog → Posts (migration 031): our own posts with a content-block body, cover image, excerpt, date, tags, and authors shown as person tiles, either People records or a guest name and photo. A post is a draft until published; Listed works as it does elsewhere. Posts are on the QR page too. Admin → Blog → Community section: the first section of the Community page, with its heading and blurb from the admin, in two halves, each pinned first and then newest up to its slots. Our posts come from blog_posts; community posts are pinned link or video cards (reusing featured cards and Fetch preview), then the newest items from a list of RSS or Atom feeds. Feeds are read through the link preview's guarded fetch and cached for 30 minutes, and a failing feed keeps its last good items. content_blocks and featured_cards are rebuilt to accept the new owner kinds. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
71 lines
2.4 KiB
TypeScript
71 lines
2.4 KiB
TypeScript
/* ═══════════════════════════════════════════════════════════════
|
|
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
|
|
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 = {
|
|
title?: string | null
|
|
blurb?: string | null
|
|
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<BlogPostRecord> =>
|
|
useRecord<BlogPostRecord>(detailPath('/blog', id), 'post')
|
|
|
|
export const useCommunityBlog = (): Resource<CommunityBlog> =>
|
|
useRecord<CommunityBlog>('/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' })
|
|
}
|