Files
chart-sins/src/components/VegaChart.astro
T
Claude dc0ce07dce Add OpenGraph/Twitter cards, generated per sin at build time
Link previews are the funnel for a "send the link" site, so give every sin
a share-optimized card.

- og/twitter meta tags on every page (poke as description, canonical URL,
  summary_large_image)
- Per-sin 1200x630 card generated at build: the poke, the before/after
  charts (uniform height so tall vconcat charts fit), severity meter,
  category, and short citations — composed with satori, rasterized with
  @resvg/resvg-js, no browser needed
- Default brand card for the homepage and canon
- Shared chart pipeline extracted to lib/renderChart.ts (used by both the
  on-page component and the card generator)
- Bundle three IBM Plex TTF weights for the rasterizer

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XPEvmMbac2fCvKXpQcovj8
2026-08-05 14:03:40 +00:00

44 lines
1.2 KiB
Plaintext

---
// Build-time Vega-Lite renderer.
//
// Runs only during `astro build` (and dev SSR), never in the browser: it
// compiles a Vega-Lite spec to Vega with the site theme, renders it headlessly
// to a static SVG string, and inlines it. Zero client-side JavaScript, no Vega
// runtime shipped.
//
// The chart sits on a fixed light canvas (--chart-canvas) in both themes, so
// this single baked render keeps AA contrast in light and dark.
import type { TopLevelSpec } from 'vega-lite';
import { renderChartSvg } from '../lib/renderChart';
interface Props {
spec: TopLevelSpec;
title: string;
caption?: string;
}
const { spec, title, caption } = Astro.props;
let svg = '';
let error: string | null = null;
try {
svg = await renderChartSvg(spec);
} catch (e) {
error = e instanceof Error ? e.message : String(e);
console.error(`[VegaChart] failed to render "${title}": ${error}`);
}
---
<figure class="vega-chart" role="group" aria-label={title}>
{error ? (
<div class="vega-chart__error">
<strong>Chart failed to render.</strong>
<code>{error}</code>
</div>
) : (
<div class="vega-chart__svg" set:html={svg} />
)}
{caption && <figcaption>{caption}</figcaption>}
</figure>