NGU-Web/src/pages/BlogPost.tsx
Zaldimmar dc53af238f Add a Request form, with files in Google Drive and email notices
One form at /request for blog posts, events, and new or updated
chapters, regions (updates only), partners, teams, awards and people.
?type= opens it on one; buttons on the Community sections, blog posts,
Retreats and the front page calendar do. Files (.docx, PDF, JPEG, PNG)
go to a Google Drive folder through a service account.

Requests are feedback rows of type 'content' (migration 046), in a
third Forms queue: files download from Drive, a .docx can become a
draft blog post, and deleting a request deletes its files. New content
and data requests email the addresses in Site settings through Gmail.

Setup: docs/google-drive-and-mail.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 15:54:00 -05:00

194 lines
6.5 KiB
TypeScript

/* ═══════════════════════════════════════════════════════════════
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 { mediaUrl } from "../lib/media.ts"
import { postDate, useBlogPost } from "../lib/useBlog.ts"
import { accentText, BRAND } from "../lib/color.ts"
import PostContents from "../components/PostContents.tsx"
import { headingAnchors } from "../lib/contents.ts"
import QrCode from "../components/QrCode.tsx"
import RequestLink from "../components/RequestLink.tsx"
import { siteUrl } from "../lib/site.ts"
import { FilePdf } from "@phosphor-icons/react"
const BODY = "var(--color-muted)"
/* 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}
/>
)
}
// Two headings or more make a list worth showing.
const contents = post.show_contents ? headingAnchors(post.blocks).entries : []
const withContents = contents.length >= 2
const postUrl = siteUrl(`/blog/${post.id}`)
const date = postDate(post.published_on)
const cover = mediaUrl(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: mediaUrl(author.photo),
})),
...(post.guest
? [
{
name: post.guest.name,
title: "Guest author",
photo: mediaUrl(post.guest.photo),
},
]
: []),
]
const sections: ShellSection[] = [
{
id: "post",
title: "Post",
accent: BRAND,
background: "var(--color-surface)",
content: (
<div
className={
withContents
? "mx-auto grid max-w-6xl gap-8 px-6 lg:grid-cols-[14rem_minmax(0,1fr)] lg:gap-12 print:block"
: "contents"
}
>
{withContents && <PostContents entries={contents} />}
<article
className={
withContents
? "min-w-0 max-w-3xl space-y-8"
: "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: "var(--color-tint)",
color: accentText(BRAND),
}}
>
{tag}
</span>
))}
<button
type="button"
onClick={() => window.print()}
className="ml-auto inline-flex items-center gap-1.5 rounded-full border border-link px-3 py-1 font-semibold text-link transition-colors hover:bg-tint print:hidden"
>
<FilePdf size={16} weight="bold" aria-hidden="true" />
Download PDF
</button>
<Link
to={BACK.to}
className="hover:underline print:hidden"
style={{ color: accentText(BRAND) }}
>
{BACK.label}
</Link>
</div>
{cover && (
<img
src={cover}
alt={post.cover_alt ?? ""}
className="aspect-video w-full rounded-2xl object-cover"
/>
)}
<ContentBlocks blocks={post.blocks} accent={BRAND} />
<div className="flex flex-wrap items-center gap-3 border-t border-brand/15 pt-6 text-sm text-muted print:hidden">
Have a story to share?
<RequestLink type="blog" label="Write for the blog" />
</div>
{/* Only on paper (Download PDF): where the post lives online,
as a link and as a code to scan. */}
<footer className="hidden break-inside-avoid items-center gap-6 border-t border-brand/20 pt-6 print:flex">
<QrCode value={postUrl} label={`QR code for ${postUrl}`} className="h-28 w-28 shrink-0" />
<p className="text-sm text-body">
Read this post online at
<br />
<span className="font-semibold text-link">{postUrl}</span>
</p>
</footer>
</article>
</div>
),
},
]
if (authors.length > 0) {
sections.push({
id: "authors",
title: authors.length === 1 ? "About the author" : "About the authors",
accent: BRAND,
background: "var(--color-tint)",
content: (
<div className="mx-auto max-w-6xl px-6">
<PeopleTiles size="md" accent={BRAND} people={authors} />
</div>
),
})
}
return (
<PageShell
title={post.title}
intro={post.excerpt ?? undefined}
sections={sections}
/>
)
}