diff --git a/server/src/routes/blog.js b/server/src/routes/blog.js index 9407477..d6c890a 100644 --- a/server/src/routes/blog.js +++ b/server/src/routes/blog.js @@ -80,6 +80,24 @@ function shapeSummary(row, authors, body) { }; } +/* A person's page: the published, listed posts they're an author + of, newest first, as the same summaries the blog section shows. + routes/people.js adds them to /people/:id. */ +export function postsBy(db, personId) { + const rows = db + .prepare( + `SELECT b.* FROM blog_posts b + JOIN blog_post_authors a ON a.post_id = b.id AND a.person_id = ? + WHERE b.is_published = 1 AND b.is_listed = 1 + ORDER BY b.published_on IS NULL, b.published_on DESC, b.created_at DESC`, + ) + .all(personId); + const ids = rows.map((row) => row.id); + const authors = loadAuthors(db, ids); + const bodies = loadBlocks(db, "blog_post", ids, "body"); + return rows.map((row) => shapeSummary(row, authors.get(row.id) ?? [], bodies.get(row.id) ?? [])); +} + /* ── One post ──────────────────────────────────────────────── */ blog.get("/blog/:id", (c) => { diff --git a/server/src/routes/people.js b/server/src/routes/people.js index 8200c24..38cb92f 100644 --- a/server/src/routes/people.js +++ b/server/src/routes/people.js @@ -22,6 +22,7 @@ import { Hono } from "hono"; import { asBool, json, loadOwned, marks, paragraphs, splitLinks } from "../shape.js"; +import { postsBy } from "./blog.js"; const people = new Hono(); @@ -284,6 +285,8 @@ people.get("/people/:id", (c) => { roles, events: [...byEvent.values()], awards, + // Blog posts they wrote (published and listed). + posts: postsBy(db, id), }, }); }); diff --git a/src/lib/useContent.ts b/src/lib/useContent.ts index b7b483f..34a31b5 100644 --- a/src/lib/useContent.ts +++ b/src/lib/useContent.ts @@ -11,6 +11,7 @@ * hrefs.ts has already logged the component that produced it. */ +import type { BlogPostSummary } from './useBlog.ts' import { detailPath } from './hrefs.ts' import { useRecord, type Resource } from './useRecord.ts' import type { EventType } from './eventTypes.ts' @@ -356,6 +357,8 @@ export type PersonRecord = { roles: PersonRole[] events: PersonEvent[] awards: PersonAward[] + /** Blog posts they wrote, newest first. */ + posts: BlogPostSummary[] } export const usePerson = (id?: string): Resource => diff --git a/src/pages/PersonDetail.tsx b/src/pages/PersonDetail.tsx index 274eab7..b3eab74 100644 --- a/src/pages/PersonDetail.tsx +++ b/src/pages/PersonDetail.tsx @@ -24,6 +24,7 @@ import PageShell, { type ShellSection } from '../components/PageShell.tsx' import PageState from '../components/PageState.tsx' import PlatformIcon from '../components/PlatformIcon.tsx' import ContentBlocks from '../components/ContentBlocks.tsx' +import { PostCard } from './sections/CommunityBlog.tsx' import { usePerson, type PersonEvent, @@ -190,6 +191,24 @@ export default function PersonDetail() { }) } + if (person.posts?.length > 0) { + sections.push({ + id: 'posts', + title: 'Blog posts', + accent, + background: BACKGROUNDS[sections.length % 2], + content: ( +
+ +
+ ), + }) + } + return ( ) diff --git a/src/pages/sections/CommunityBlog.tsx b/src/pages/sections/CommunityBlog.tsx index dd7e4f0..3d733a0 100644 --- a/src/pages/sections/CommunityBlog.tsx +++ b/src/pages/sections/CommunityBlog.tsx @@ -36,7 +36,8 @@ const DEFAULTS = { const EXCERPT_CHARS = 180 -function PostCard({ post, accent }: { post: BlogPostSummary; accent: string }) { +/* One post as a card; person pages list their posts with it too. */ +export function PostCard({ post, accent }: { post: BlogPostSummary; accent: string }) { const cover = useSmallImage(mediaUrl(post.cover_image)) const date = postDate(post.published_on) const authors = post.authors.map((author) => author.name).join(', ')