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
|
|
@ -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> =>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue