Let a blog post be downloaded as a PDF

Download PDF beside the byline opens the browser's print dialog (Save
as PDF) with a print layout: the site's header, footer and notices
hidden, the contents column dropped, the light palette whatever the
screen shows, and at the bottom the post's link and a QR code of it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-09-29 15:34:43 -05:00
parent c03914a210
commit 5dceeb5860
4 changed files with 61 additions and 7 deletions

View file

@ -175,7 +175,7 @@ export default function Layout() {
{/* ── NAV ─────────────────────────────────────────────── */} {/* ── NAV ─────────────────────────────────────────────── */}
<header <header
ref={headerRef} ref={headerRef}
className="fixed top-0 left-0 right-0 z-50 backdrop-blur-md" className="fixed top-0 left-0 right-0 z-50 backdrop-blur-md print:hidden"
inert={mobileMenuOpen} inert={mobileMenuOpen}
> >
@ -273,7 +273,7 @@ export default function Layout() {
</header> </header>
{/* Keeps page content clear of the fixed header */} {/* Keeps page content clear of the fixed header */}
<div aria-hidden style={{ height: headerHeight }} /> <div aria-hidden className="print:hidden" style={{ height: headerHeight }} />
{/* Page content */} {/* Page content */}
<main id="main" tabIndex={-1} className="outline-none" inert={mobileMenuOpen}> <main id="main" tabIndex={-1} className="outline-none" inert={mobileMenuOpen}>
@ -283,7 +283,7 @@ export default function Layout() {
</main> </main>
{/*Site Footer applied to every page*/} {/*Site Footer applied to every page*/}
<div inert={mobileMenuOpen}> <div inert={mobileMenuOpen} className="print:hidden">
<Footer /> <Footer />
<PrivacyNotice /> <PrivacyNotice />
</div> </div>

View file

@ -74,7 +74,7 @@ export default function PostContents({ entries }: { entries: ContentsEntry[] })
const lit = useLit(entries) const lit = useLit(entries)
return ( return (
<> <>
<details className="rounded-2xl border border-brand/20 bg-tint-soft p-4 lg:hidden"> <details className="rounded-2xl border border-brand/20 bg-tint-soft p-4 lg:hidden print:hidden">
<summary className="cursor-pointer font-semibold text-ink">On this page</summary> <summary className="cursor-pointer font-semibold text-ink">On this page</summary>
<div className="mt-3"> <div className="mt-3">
<List entries={entries} lit={lit} /> <List entries={entries} lit={lit} />
@ -82,7 +82,7 @@ export default function PostContents({ entries }: { entries: ContentsEntry[] })
</details> </details>
<nav <nav
aria-label="On this page" aria-label="On this page"
className="sticky hidden self-start lg:block" className="sticky hidden self-start lg:block print:hidden"
style={{ top: 'calc(var(--header-h, 5rem) + 1.5rem)' }} style={{ top: 'calc(var(--header-h, 5rem) + 1.5rem)' }}
> >
<p className="mb-2 px-3 text-sm font-semibold text-ink">On this page</p> <p className="mb-2 px-3 text-sm font-semibold text-ink">On this page</p>

View file

@ -149,6 +149,37 @@ h1, h2, h3, h4, h5, h6 {
} }
} }
/* Printing (a blog post's Download PDF, or any page): the light
palette whatever the screen shows, since paper is white and dark
mode's pale text would barely print; and backgrounds kept, so the
tinted panels and table rows come out as on screen. */
@media print {
:root,
:root[data-theme="dark"] {
--color-ink: #073d4a;
--color-body: #26454c;
--color-muted: #4a6b72;
--color-link: #0f7183;
--color-brand: #138ba0;
--color-surface: #ffffff;
--color-tint: #eef9fb;
--color-tint-soft: #f6fbfc;
--color-danger: #b3261e;
--color-danger-tint: #fdf3f2;
--accent-text-mix: 100%;
color-scheme: light;
print-color-adjust: exact;
}
.logo-plate {
background: none !important;
padding: 0 !important;
}
}
@page {
margin: 1.5cm;
}
/* Church Center's giving modal (Giving.tsx) is a transparent iframe /* Church Center's giving modal (Giving.tsx) is a transparent iframe
over the whole page, drawn for light pages. On a dark page the over the whole page, drawn for light pages. On a dark page the
browser sees the iframe's scheme differ from ours and paints its browser sees the iframe's scheme differ from ours and paints its

View file

@ -21,6 +21,9 @@ import { postDate, useBlogPost } from "../lib/useBlog.ts"
import { accentText, BRAND } from "../lib/color.ts" import { accentText, BRAND } from "../lib/color.ts"
import PostContents from "../components/PostContents.tsx" import PostContents from "../components/PostContents.tsx"
import { headingAnchors } from "../lib/contents.ts" import { headingAnchors } from "../lib/contents.ts"
import QrCode from "../components/QrCode.tsx"
import { siteUrl } from "../lib/site.ts"
import { FilePdf } from "@phosphor-icons/react"
const BODY = "var(--color-muted)" const BODY = "var(--color-muted)"
@ -49,6 +52,7 @@ export default function BlogPost() {
const contents = post.show_contents ? headingAnchors(post.blocks).entries : [] const contents = post.show_contents ? headingAnchors(post.blocks).entries : []
const withContents = contents.length >= 2 const withContents = contents.length >= 2
const postUrl = siteUrl(`/blog/${post.id}`)
const date = postDate(post.published_on) const date = postDate(post.published_on)
const cover = mediaUrl(post.cover_image) const cover = mediaUrl(post.cover_image)
const byline = [ const byline = [
@ -85,7 +89,7 @@ export default function BlogPost() {
<div <div
className={ className={
withContents withContents
? "mx-auto grid max-w-6xl gap-8 px-6 lg:grid-cols-[14rem_minmax(0,1fr)] lg:gap-12" ? "mx-auto grid max-w-6xl gap-8 px-6 lg:grid-cols-[14rem_minmax(0,1fr)] lg:gap-12 print:block"
: "contents" : "contents"
} }
> >
@ -117,9 +121,17 @@ export default function BlogPost() {
{tag} {tag}
</span> </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 <Link
to={BACK.to} to={BACK.to}
className="ml-auto hover:underline" className="hover:underline print:hidden"
style={{ color: accentText(BRAND) }} style={{ color: accentText(BRAND) }}
> >
{BACK.label} {BACK.label}
@ -135,6 +147,17 @@ export default function BlogPost() {
)} )}
<ContentBlocks blocks={post.blocks} accent={BRAND} /> <ContentBlocks blocks={post.blocks} accent={BRAND} />
{/* 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> </article>
</div> </div>
), ),