Each page is now a list of sections edited in Admin → Pages: a title (30 characters at most, for the side nav), URL ID, blurb and accent, its own content blocks, and an optional preset (Community blog, groups map, region list, partner cards, events, timeline, NGU's details). Migration 056 seeds every page as the code drew it and moves the Organization editor's blocks and volunteering into its sections. The Community blog's settings move into the Community editor. The header, footer and side nav read each page's sections from the API. The admin engine reads and writes nested collections to any depth. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
72 lines
2.5 KiB
TypeScript
72 lines
2.5 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
|
|
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<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' })
|
|
}
|