Add a blog: posts at /blog/:id and a Community page section

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>
This commit is contained in:
Zaldimmar 2026-09-27 16:27:00 -05:00
parent d4f65d93b4
commit d374f9ac17
21 changed files with 1275 additions and 15 deletions

View file

@ -0,0 +1,145 @@
/* ═══════════════════════════════════════════════════════════════
COMMUNITY BLOG
The Community page's blog section (Admin → Blog → Community
section). Two halves, each pinned first and then newest, as
routes/blog.js decides:
our posts cards for our own /blog/:id pages
community posts featured cards (pinned by hand, or the
newest from the listed feeds), drawn by
FeaturedCards, with a button to the Substack
The section's heading and blurb come from the same record; the
page reads them through the same cached request (Community.tsx).
A half with nothing in it isn't drawn.
═══════════════════════════════════════════════════════════════ */
import { Link } from 'react-router-dom'
import FeaturedCards from '../../components/FeaturedCards.tsx'
import PlatformIcon from '../../components/PlatformIcon.tsx'
import { blogHref } from '../../lib/hrefs.ts'
import { blogImage } from '../../lib/media.ts'
import { preview } from '../../lib/text.ts'
import { postDate, useCommunityBlog, type BlogPostSummary } from '../../lib/useBlog.ts'
import HomeLink from './home/HomeLink.tsx'
/* Headings for a half the admin didn't title. */
const DEFAULTS = {
internal: 'From NGU',
external: 'From our community',
externalLabel: 'Read more on Substack',
}
const EXCERPT_CHARS = 180
function PostCard({ post, accent }: { post: BlogPostSummary; accent: string }) {
const cover = blogImage(post.cover_image)
const date = postDate(post.published_on)
const authors = post.authors.map((author) => author.name).join(', ')
return (
<li className="relative flex flex-col overflow-hidden rounded-2xl border border-[#138ba0]/15 bg-white shadow-sm transition-shadow hover:shadow-lg">
{cover ? (
<img src={cover} alt="" loading="lazy" className="aspect-video w-full object-cover" />
) : (
<div className="aspect-video w-full bg-gradient-to-br from-[#eef9fb] to-[#d9f0f3]" />
)}
<div className="flex flex-1 flex-col p-6">
{(date || post.tags.length > 0) && (
<p className="text-xs font-bold uppercase tracking-[0.2em]" style={{ color: accent }}>
{[date, ...post.tags].filter(Boolean).join(' · ')}
</p>
)}
<h4 className="mt-2 font-display text-xl font-extrabold leading-snug text-[#073d4a]">
<Link
to={blogHref(post.id)}
className="after:absolute after:inset-0 after:rounded-2xl after:content-[''] hover:underline"
>
{post.title}
</Link>
</h4>
{post.excerpt && (
<p className="mt-2 leading-relaxed text-[#4a6b72]">{preview(post.excerpt, EXCERPT_CHARS)}</p>
)}
{authors && <p className="mt-auto pt-4 text-sm font-medium text-[#26454c]">By {authors}</p>}
</div>
</li>
)
}
function Subheading({ children, accent }: { children: string; accent: string }) {
return (
<h3 className="text-2xl font-800" style={{ color: accent }}>
{children}
</h3>
)
}
export default function CommunityBlog({ accent = '#138ba0' }: { accent?: string }) {
const { data: blog, loading, error, reload } = useCommunityBlog()
if (!blog) {
return (
<div className="mx-auto max-w-6xl px-6 text-[#4a6b72]">
{loading ? (
'Loading…'
) : (
<>
Couldn’t load the blog. {error}{' '}
<button type="button" onClick={reload} className="underline" style={{ color: accent }}>
Try again
</button>
</>
)}
</div>
)
}
const { internal, external } = blog
const hasInternal = internal.posts.length > 0
const hasExternal = external.cards.length > 0 || Boolean(external.url)
if (!hasInternal && !hasExternal) {
return <p className="mx-auto max-w-6xl px-6 text-center text-[#4a6b72]">· Posts coming soon ·</p>
}
return (
<div className="mx-auto max-w-6xl space-y-16 px-6">
{hasInternal && (
<div>
<Subheading accent={accent}>{internal.title || DEFAULTS.internal}</Subheading>
<ul className="mt-6 grid gap-6 sm:grid-cols-2 lg:grid-cols-3">
{internal.posts.map((post) => (
<PostCard key={post.id} post={post} accent={accent} />
))}
</ul>
</div>
)}
{hasExternal && (
<div>
<div className="flex flex-wrap items-end gap-4">
<Subheading accent={accent}>{external.title || DEFAULTS.external}</Subheading>
{external.url && (
<HomeLink
url={external.url}
className="ml-auto inline-flex items-center gap-2 rounded-full px-5 py-2 text-sm font-semibold text-white transition-transform hover:scale-105"
style={{ background: accent }}
>
<PlatformIcon platform={/substack\.com/i.test(external.url) ? 'substack' : null} />
{external.label || DEFAULTS.externalLabel}
</HomeLink>
)}
</div>
{external.cards.length > 0 && (
<div className="mt-6">
<FeaturedCards cards={external.cards} />
</div>
)}
</div>
)}
</div>
)
}