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:
parent
d4f65d93b4
commit
d374f9ac17
21 changed files with 1275 additions and 15 deletions
114
src/pages/BlogPost.tsx
Normal file
114
src/pages/BlogPost.tsx
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
BLOG POST: /blog/:id
|
||||
|
||||
One of our own posts: cover, date and tags, the content-block
|
||||
body, then its authors as person tiles. Authors are published
|
||||
people (linked to their pages) and, when the post names one, a
|
||||
guest with no people record (a tile that links nowhere).
|
||||
|
||||
There's no /blog index on purpose: the Community page's blog
|
||||
section is where posts are listed, so "back" goes there.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
import { Link, useParams } from 'react-router-dom'
|
||||
|
||||
import PageShell, { type ShellSection } from '../components/PageShell.tsx'
|
||||
import PageState from '../components/PageState.tsx'
|
||||
import ContentBlocks from '../components/ContentBlocks.tsx'
|
||||
import PeopleTiles from '../components/PeopleTiles.tsx'
|
||||
import { blogImage, personPhoto } from '../lib/media.ts'
|
||||
import { postDate, useBlogPost } from '../lib/useBlog.ts'
|
||||
|
||||
const ACCENT = '#138ba0'
|
||||
const BODY = '#4a6b72'
|
||||
|
||||
/* Where "back" goes: the section on the Community page. */
|
||||
const BACK = { to: '/community#blog', label: 'Community Blog' }
|
||||
|
||||
export default function BlogPost() {
|
||||
const { id } = useParams()
|
||||
const { data: post, loading, error, notFound, reload } = useBlogPost(id)
|
||||
|
||||
if (!post) {
|
||||
return (
|
||||
<PageState
|
||||
loading={loading}
|
||||
error={error}
|
||||
notFound={notFound}
|
||||
onRetry={reload}
|
||||
noun="post"
|
||||
backTo={BACK.to}
|
||||
backLabel={BACK.label}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
const date = postDate(post.published_on)
|
||||
const cover = blogImage(post.cover_image)
|
||||
const byline = [
|
||||
...post.authors.map((author) => author.name),
|
||||
...(post.guest ? [post.guest.name] : []),
|
||||
].join(', ')
|
||||
|
||||
const authors = [
|
||||
...post.authors.map((author) => ({
|
||||
id: author.id,
|
||||
name: author.name,
|
||||
tagline: author.tagline,
|
||||
pronouns: author.pronouns,
|
||||
photo: personPhoto(author.photo),
|
||||
})),
|
||||
...(post.guest ? [{ name: post.guest.name, title: 'Guest author', photo: blogImage(post.guest.photo) }] : []),
|
||||
]
|
||||
|
||||
const sections: ShellSection[] = [
|
||||
{
|
||||
id: 'post',
|
||||
title: 'Post',
|
||||
accent: ACCENT,
|
||||
background: '#ffffff',
|
||||
content: (
|
||||
<article className="mx-auto max-w-3xl space-y-8 px-6">
|
||||
<div className="flex flex-wrap items-center gap-x-4 gap-y-2 text-sm" style={{ color: BODY }}>
|
||||
{date && <time dateTime={post.published_on ?? undefined}>{date}</time>}
|
||||
{byline && <span>By {byline}</span>}
|
||||
{post.tags.map((tag) => (
|
||||
<span
|
||||
key={tag}
|
||||
className="rounded-full px-3 py-0.5 text-xs font-semibold"
|
||||
style={{ background: '#eef9fb', color: ACCENT }}
|
||||
>
|
||||
{tag}
|
||||
</span>
|
||||
))}
|
||||
<Link to={BACK.to} className="ml-auto hover:underline" style={{ color: ACCENT }}>
|
||||
{BACK.label}
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
{cover && (
|
||||
<img src={cover} alt="" className="aspect-video w-full rounded-2xl object-cover" />
|
||||
)}
|
||||
|
||||
<ContentBlocks blocks={post.blocks} accent={ACCENT} />
|
||||
</article>
|
||||
),
|
||||
},
|
||||
]
|
||||
|
||||
if (authors.length > 0) {
|
||||
sections.push({
|
||||
id: 'authors',
|
||||
title: authors.length === 1 ? 'About the author' : 'About the authors',
|
||||
accent: ACCENT,
|
||||
background: '#eef9fb',
|
||||
content: (
|
||||
<div className="mx-auto max-w-6xl px-6">
|
||||
<PeopleTiles size="md" accent={ACCENT} people={authors} />
|
||||
</div>
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
return <PageShell title={post.title} intro={post.excerpt ?? undefined} sections={sections} />
|
||||
}
|
||||
|
|
@ -3,15 +3,23 @@ import { useSectionManifest } from "../lib/sections.tsx";
|
|||
import OrgListMap, { OrgMapToggle } from "./sections/OrgList-Map.tsx";
|
||||
import OrgListVertical from "./sections/OrgList-Vertical.tsx";
|
||||
import OrgListCards from "./sections/OrgList-Card.tsx";
|
||||
import CommunityBlog from "./sections/CommunityBlog.tsx";
|
||||
import { useCommunityBlog } from "../lib/useBlog.ts";
|
||||
|
||||
/* ═══════════════════════════════════════════════════════════════
|
||||
COMMUNITY PAGE
|
||||
|
||||
Two views of the organizations table. The map is filtered to
|
||||
chapters; the vertical list is filtered to regions. Same rows,
|
||||
same endpoint, different shape on the page.
|
||||
The blog first, then two views of the organizations table. The
|
||||
map is filtered to chapters; the vertical list is filtered to
|
||||
regions. Same rows, same endpoint, different shape on the page.
|
||||
|
||||
The blog's heading and blurb are the admin's (Blog → Community
|
||||
section), so that one entry is built here from the same cached
|
||||
request CommunityBlog makes for its posts.
|
||||
═══════════════════════════════════════════════════════════════ */
|
||||
|
||||
const BLOG_DEFAULT_TITLE = "Community Blog";
|
||||
|
||||
const SECTIONS = [
|
||||
{
|
||||
id: "chapters",
|
||||
|
|
@ -58,7 +66,19 @@ const SECTIONS = [
|
|||
];
|
||||
|
||||
export default function CommunityPage() {
|
||||
const sections = useSectionManifest(SECTIONS);
|
||||
const { data: blog } = useCommunityBlog();
|
||||
|
||||
const sections = useSectionManifest([
|
||||
{
|
||||
id: "blog",
|
||||
title: blog?.title || BLOG_DEFAULT_TITLE,
|
||||
blurb: blog?.blurb ?? undefined,
|
||||
accent: "#138ba0",
|
||||
background: "#ffffff",
|
||||
Component: CommunityBlog,
|
||||
},
|
||||
...SECTIONS,
|
||||
]);
|
||||
|
||||
return (
|
||||
<PageShell
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ const SECTIONS = [
|
|||
id: 'make',
|
||||
title: 'Make a QR code',
|
||||
blurb:
|
||||
'Pick a page from the main navigation, or any event, organization, team, award or person on the site. The code always points at the live site.',
|
||||
'Pick a page from the main navigation, or any event, organization, team, award, person or blog post on the site. The code always points at the live site.',
|
||||
accent: '#138ba0',
|
||||
background: '#eef9fb',
|
||||
content: (
|
||||
|
|
|
|||
|
|
@ -70,6 +70,17 @@ export const CMS_NAV = [
|
|||
label: "Front page",
|
||||
blurb: "The hero, its photos or livestream, and which bands the home page draws.",
|
||||
},
|
||||
// Posts, and the Community page section that lists them. Two
|
||||
// entities, one tab, like Organizations with Teams and Awards.
|
||||
{
|
||||
to: "/admin/blog_posts",
|
||||
label: "Blog",
|
||||
blurb: "Posts of our own, and the Community page's blog section.",
|
||||
children: [
|
||||
{ to: "/admin/blog_posts", label: "Posts" },
|
||||
{ to: "/admin/community_page", label: "Community section" },
|
||||
],
|
||||
},
|
||||
// Not an entity: the uploaded-image library every image field
|
||||
// picks from. Its own page, AdminMedia.tsx.
|
||||
{
|
||||
|
|
|
|||
145
src/pages/sections/CommunityBlog.tsx
Normal file
145
src/pages/sections/CommunityBlog.tsx
Normal 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>
|
||||
)
|
||||
}
|
||||
|
|
@ -24,7 +24,7 @@ import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
|
|||
|
||||
import QrCode from '../../components/QrCode.tsx'
|
||||
import { NAV_ACTIONS, PAGE_LINKS, PAGE_SECTIONS } from '../../navConfig.ts'
|
||||
import { awardHref, eventHref, orgHref, personHref, teamHref } from '../../lib/hrefs.ts'
|
||||
import { awardHref, blogHref, eventHref, orgHref, personHref, teamHref } from '../../lib/hrefs.ts'
|
||||
import { siteUrl } from '../../lib/site.ts'
|
||||
import { useDirectory, type Directory } from '../../lib/useContent.ts'
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ const MUTED = '#4a6b72'
|
|||
anything bigger should use the SVG. */
|
||||
const PNG_SIZE = 1024
|
||||
|
||||
type Kind = 'pages' | 'events' | 'organizations' | 'teams' | 'awards' | 'people'
|
||||
type Kind = 'pages' | 'events' | 'organizations' | 'teams' | 'awards' | 'people' | 'blog_posts'
|
||||
|
||||
const KINDS: Array<[Kind, string]> = [
|
||||
['pages', 'Main navigation'],
|
||||
|
|
@ -44,6 +44,7 @@ const KINDS: Array<[Kind, string]> = [
|
|||
['teams', 'Teams'],
|
||||
['awards', 'Awards'],
|
||||
['people', 'People'],
|
||||
['blog_posts', 'Blog posts'],
|
||||
]
|
||||
|
||||
/* Organizations are grouped by kind in the dropdown, in this order. */
|
||||
|
|
@ -106,6 +107,8 @@ function groupsFor(kind: Kind, directory: Directory | null): Group[] {
|
|||
return [{ choices: directory.awards.map((a) => ({ path: awardHref(a.id), label: a.name })) }]
|
||||
case 'people':
|
||||
return [{ choices: directory.people.map((p) => ({ path: personHref(p.id), label: p.name })) }]
|
||||
case 'blog_posts':
|
||||
return [{ choices: directory.blog_posts.map((b) => ({ path: blogHref(b.id), label: b.name })) }]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue