blog: author is jsonb, render a name not [object Object]

The blog_posts.author column is jsonb (e.g. { name, url }), not text.
Extract a display name for the byline and JSON-LD instead of rendering the
object directly.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MxNif5tsYq4LczgG7aE8Jp
This commit is contained in:
Anthony Ettinger 2026-09-12 15:20:05 +00:00
parent 0d37c196c7
commit 8c5c5d866b

View file

@ -21,9 +21,18 @@ type PostRow = {
// When set, it is the canonical for search engines and is shown to readers, // When set, it is the canonical for search engines and is shown to readers,
// so a cross-post never competes with its source for the same words. // so a cross-post never competes with its source for the same words.
canonical_url: string | null; canonical_url: string | null;
author: string | null; // Stored as jsonb: an object like { name, url }, or occasionally a bare
// string. Never rendered directly, or an object prints as [object Object].
author: { name?: string; url?: string } | string | null;
}; };
/** A display name from the jsonb author, whatever shape it took. */
function authorName(author: PostRow["author"]): string {
if (!author) return "";
if (typeof author === "string") return author;
return typeof author.name === "string" ? author.name : "";
}
const SITE_URL = (process.env.PUBLIC_URL ?? "https://logicsrc.com").replace(/\/$/, ""); const SITE_URL = (process.env.PUBLIC_URL ?? "https://logicsrc.com").replace(/\/$/, "");
async function loadPost(slug: string): Promise<PostRow | null> { async function loadPost(slug: string): Promise<PostRow | null> {
@ -93,9 +102,10 @@ export default async function BlogPostPage({
url: `${SITE_URL}/blog/${post.slug}`, url: `${SITE_URL}/blog/${post.slug}`,
// For a guest post this is the original; search engines follow it. // For a guest post this is the original; search engines follow it.
mainEntityOfPage: canonical, mainEntityOfPage: canonical,
...(post.author ? { author: { "@type": "Person", name: post.author } } : {}), ...(authorName(post.author) ? { author: { "@type": "Person", name: authorName(post.author) } } : {}),
publisher: { "@id": `${SITE_URL}/#organization` }, publisher: { "@id": `${SITE_URL}/#organization` },
}; };
const byline = authorName(post.author);
let originHost = ""; let originHost = "";
if (post.canonical_url) { if (post.canonical_url) {
try { try {
@ -123,7 +133,7 @@ export default async function BlogPostPage({
</h1> </h1>
<div style={{ color: "#5b6b7a", fontSize: "0.85rem", marginBottom: "2rem" }}> <div style={{ color: "#5b6b7a", fontSize: "0.85rem", marginBottom: "2rem" }}>
{formatDate(post.published_at)} {formatDate(post.published_at)}
{post.author ? ` · ${post.author}` : ""} {byline ? ` · ${byline}` : ""}
{post.canonical_url ? ( {post.canonical_url ? (
<> <>
{" · "} {" · "}