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
|
|
@ -25,6 +25,7 @@ import OrganizationDetail from './pages/OrganizationDetail.tsx'
|
|||
import TeamDetail from './pages/TeamDetail.tsx'
|
||||
import AwardDetail from './pages/AwardDetail.tsx'
|
||||
import PersonDetail from './pages/PersonDetail.tsx'
|
||||
import BlogPost from './pages/BlogPost.tsx'
|
||||
|
||||
/*Admin Pages*/
|
||||
import AdminLayout from "./pages/admin/AdminLayout.tsx";
|
||||
|
|
@ -61,6 +62,7 @@ export default function App() {
|
|||
<Route path="/teams/:id" element={<TeamDetail />} />
|
||||
<Route path="/awards/:id" element={<AwardDetail />} />
|
||||
<Route path="/people/:id" element={<PersonDetail />} />
|
||||
<Route path="/blog/:id" element={<BlogPost />} />
|
||||
<Route path="leadership" element={<Leadership />} />
|
||||
<Route path="resources" element={<Resources />} />
|
||||
<Route path="history" element={<History />} />
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import {
|
|||
awardLogo,
|
||||
blockMedia,
|
||||
eventBackground,
|
||||
blogImage,
|
||||
eventLogo,
|
||||
featuredImage,
|
||||
heroPhoto,
|
||||
|
|
@ -1299,6 +1300,181 @@ const frontPage = {
|
|||
],
|
||||
};
|
||||
|
||||
/* ── Blog (031_blog.sql) ─────────────────────────────────────────
|
||||
Posts at /blog/:id, and the Community page's blog section. The
|
||||
section's community posts reuse the featured cards, limited to
|
||||
links: a pinned Substack post is a link card, and Fetch preview
|
||||
fills it from the post. */
|
||||
|
||||
/* A post's body is the content blocks without the card/body choice:
|
||||
a post only has a body. */
|
||||
const blogBlocksChild = {
|
||||
...blocksChild,
|
||||
label: "Post body",
|
||||
note: "The post, top to bottom. The first paragraph doubles as the excerpt when that's left blank.",
|
||||
fields: blocksChild.fields.filter((field) => field.path !== "slot"),
|
||||
};
|
||||
|
||||
const blogPosts = {
|
||||
key: "blog_posts",
|
||||
label: "Blog posts",
|
||||
singular: "blog post",
|
||||
idLabel: "URL ID",
|
||||
slugFrom: "title",
|
||||
|
||||
list: {
|
||||
columns: [
|
||||
{ key: "title", label: "Title", primary: true },
|
||||
{ key: "published_on", label: "Date" },
|
||||
{ key: "tags", label: "Tags" },
|
||||
{ key: "is_published", label: "Live", widget: "bool" },
|
||||
{ key: "is_listed", label: "Listed", widget: "bool" },
|
||||
],
|
||||
filters: [
|
||||
{ key: "is_published", label: "Published", options: [["1", "Live"], ["0", "Draft"]] },
|
||||
{ key: "is_listed", label: "Listed", options: [["1", "Listed"], ["0", "Link only"]] },
|
||||
],
|
||||
},
|
||||
|
||||
groups: [
|
||||
{
|
||||
legend: "Post",
|
||||
fields: [
|
||||
{ path: "title", label: "Title", required: true, full: true },
|
||||
{ path: "published_on", label: "Date", widget: "date", help: "Newest first on the Community page" },
|
||||
{ path: "tags", label: "Tags", help: "Comma separated, eg. Reflection, Event recap" },
|
||||
{
|
||||
path: "excerpt",
|
||||
label: "Excerpt",
|
||||
widget: "textarea",
|
||||
full: true,
|
||||
help: "A sentence or two for the card. Default: the body's first paragraph.",
|
||||
},
|
||||
{ path: "cover_image", label: "Cover image", widget: "image", resolve: blogImage, full: true },
|
||||
],
|
||||
},
|
||||
{
|
||||
legend: "Guest author",
|
||||
note: "For a writer with no People record. People who wrote it go under Authors below; both can be set.",
|
||||
fields: [
|
||||
{ path: "guest_author", label: "Name" },
|
||||
{ path: "guest_photo", label: "Photo", widget: "image", resolve: blogImage, full: true },
|
||||
],
|
||||
},
|
||||
{
|
||||
legend: "Publishing",
|
||||
note: "A new post is a draft until Published is ticked. Unlisted posts keep their page and can still be pinned.",
|
||||
fields: [PUBLISHED_FIELD, LISTED_FIELD],
|
||||
},
|
||||
],
|
||||
|
||||
children: [
|
||||
{
|
||||
key: "authors",
|
||||
label: "Authors",
|
||||
note: "Shown as person tiles at the end of the post, in this order.",
|
||||
addLabel: "Add author",
|
||||
title: (row, options) =>
|
||||
options?.people?.find((p) => p.id === row.person_id)?.label ?? "New author",
|
||||
blank: { person_id: "" },
|
||||
fields: [
|
||||
{
|
||||
path: "person_id",
|
||||
label: "Person",
|
||||
widget: "select",
|
||||
optionsFrom: "people",
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
blogBlocksChild,
|
||||
],
|
||||
};
|
||||
|
||||
const communityPage = {
|
||||
key: "community_page",
|
||||
label: "Community blog section",
|
||||
singular: "community blog section",
|
||||
idLabel: "Page",
|
||||
singleton: "community",
|
||||
|
||||
list: { columns: [], filters: [] },
|
||||
|
||||
groups: [
|
||||
{
|
||||
legend: "Section",
|
||||
note: "The first section of the Community page.",
|
||||
fields: [
|
||||
{ path: "blog_title", label: "Heading", help: "Default: Community Blog" },
|
||||
{ path: "blog_blurb", label: "Blurb", widget: "textarea", full: true },
|
||||
],
|
||||
},
|
||||
{
|
||||
legend: "Our posts",
|
||||
note: "Pinned posts first, then the newest published, listed posts, up to the number of slots.",
|
||||
fields: [
|
||||
{ path: "internal_title", label: "Heading", help: "Default: From NGU" },
|
||||
{ path: "internal_slots", label: "Slots", widget: "number", help: "0 to 12. Default: 3" },
|
||||
],
|
||||
},
|
||||
{
|
||||
legend: "Community posts",
|
||||
note: "Pinned cards first, then the newest items from the feeds below, up to the number of slots.",
|
||||
fields: [
|
||||
{ path: "external_title", label: "Heading", help: "Default: From our community" },
|
||||
{ path: "external_slots", label: "Slots", widget: "number", help: "0 to 12. Default: 3" },
|
||||
{ path: "external_url", label: "Button link", help: "eg. https://ngu.substack.com", full: true },
|
||||
{ path: "external_label", label: "Button text", help: "Default: Read more on Substack" },
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
children: [
|
||||
{
|
||||
key: "pinned_posts",
|
||||
label: "Pinned posts (ours)",
|
||||
note: "Always shown, before the newest.",
|
||||
addLabel: "Pin a post",
|
||||
title: (row, options) =>
|
||||
options?.blog_posts?.find((p) => p.id === row.post_id)?.label ?? "New pin",
|
||||
blank: { post_id: "" },
|
||||
fields: [
|
||||
{
|
||||
path: "post_id",
|
||||
label: "Post",
|
||||
widget: "select",
|
||||
optionsFrom: "blog_posts",
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
...featuredCardsChild,
|
||||
label: "Pinned community posts",
|
||||
note: "Always shown, before the feeds' newest. Paste a post's link and press Fetch preview.",
|
||||
addLabel: "Pin a post",
|
||||
blank: { kind: "", url: "", title: "" },
|
||||
fields: featuredCardsChild.fields.map((field) =>
|
||||
field.path === "kind"
|
||||
? { ...field, options: FEATURED_KINDS.filter(([kind]) => kind !== "record") }
|
||||
: field,
|
||||
),
|
||||
},
|
||||
{
|
||||
key: "feeds",
|
||||
label: "Feeds",
|
||||
note: "RSS or Atom feeds whose newest posts fill the community slots. Read about every 30 minutes.",
|
||||
addLabel: "Add feed",
|
||||
title: (row) => row.label || row.url || "New feed",
|
||||
blank: { url: "", label: "" },
|
||||
fields: [
|
||||
{ path: "url", label: "Feed URL", required: true, full: true, help: "eg. https://ngu.substack.com/feed" },
|
||||
{ path: "label", label: "Source name", help: "Shown on its cards. Default: the feed's own title" },
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export const ADMIN_ENTITIES: Record<string, any> = {
|
||||
organizations,
|
||||
events,
|
||||
|
|
@ -1307,6 +1483,8 @@ export const ADMIN_ENTITIES: Record<string, any> = {
|
|||
awards,
|
||||
timeline,
|
||||
front_page: frontPage,
|
||||
blog_posts: blogPosts,
|
||||
community_page: communityPage,
|
||||
};
|
||||
|
||||
export function slugify(value) {
|
||||
|
|
|
|||
|
|
@ -116,6 +116,8 @@ export const awardHref = (id?: string | null) => `/awards/${checkId(id, 'awardHr
|
|||
|
||||
export const personHref = (id?: string | null) => `/people/${checkId(id, 'personHref')}`
|
||||
|
||||
export const blogHref = (id?: string | null) => `/blog/${checkId(id, 'blogHref')}`
|
||||
|
||||
export function orgHref(id?: string | null, kind?: string | null): string {
|
||||
return `${ORG_BASE[kind ?? ''] ?? '/organizations'}/${checkId(id, 'orgHref')}`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,6 +52,9 @@ export const blockMedia = inDir('/media') // ⚠ guess
|
|||
('/uploads/…'); a bare filename looks here. */
|
||||
export const featuredImage = inDir('/featured')
|
||||
|
||||
/* blog_posts.cover_image and guest_photo. Normally uploads. */
|
||||
export const blogImage = inDir('/blog')
|
||||
|
||||
/* ── By record kind ────────────────────────────────────────────
|
||||
The timeline sends `logo: { file, kind }` rather than a path,
|
||||
because v_timeline COALESCEs across five tables and only the
|
||||
|
|
|
|||
71
src/lib/useBlog.ts
Normal file
71
src/lib/useBlog.ts
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/* ═══════════════════════════════════════════════════════════════
|
||||
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' })
|
||||
}
|
||||
|
|
@ -351,6 +351,7 @@ export type Directory = {
|
|||
teams: Array<DirectoryEntry & { org_name: string }>
|
||||
awards: DirectoryEntry[]
|
||||
people: DirectoryEntry[]
|
||||
blog_posts: DirectoryEntry[]
|
||||
}
|
||||
|
||||
export const useDirectory = (): Resource<Directory> =>
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ export const PAGE_SECTIONS = {
|
|||
{ label: "Partner Events", hash: "#partner"},
|
||||
],
|
||||
"/community": [
|
||||
{ label: "Community Blog", hash: "#blog" },
|
||||
{ label: "Local Chapters", hash: "#local" },
|
||||
{ label: "Virtual Community", hash: "#virtual" },
|
||||
{ label: "Partner Organizations", hash: "#partners" },
|
||||
|
|
|
|||
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