NGU-Web/src/lib/useBlog.ts
Zaldimmar 185f9831e2 Fix accessibility found in the audit
- Text contrast: teal text and button fills use #0f7183 (5.7:1), section
  accents darkened to pass on white, solid CTA buttons instead of the
  gradient, footer and subnav text raised to white/65, event and region
  colours kept on borders and swatches with ink text
- Hidden carousel slides and collapsed past events are inert
- Admin list rows carry a real link for keyboard use
- Mobile menu is a modal dialog: focus, Escape, inert background, above
  the header
- Skip to content link, one focus-visible ring, reduced-motion rule,
  focus rings on the calendar inputs
- Region headings hold their button instead of sitting inside it
- font-700 style classes (not Tailwind v4 utilities) replaced with named
  weights, and the 700/800 font files loaded
- Migration 038: alt text for blog covers and schedule graphics; event
  logos next to their title are decorative
- Drop the Church Center script from index.html; Giving loads it itself

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 22:07:56 -05:00

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
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' })
}