// Margin annotations panel — renders at.margin.annotation records for a URL. // Gated behind ENABLE_MARGIN=true env var. import { getAnnotations, type MarginAnnotation } from "../data.ts"; function escapeHtml(str: string): string { return str .replace(/&/g, "&") .replace(//g, ">") .replace(/"/g, """); } function formatDate(iso: string): string { return new Date(iso).toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric", }); } export async function MarginPanel({ pageUrl }: { pageUrl: string }) { if (process.env.ENABLE_MARGIN !== "true") return <>; const annotations = await getAnnotations(pageUrl); if (annotations.length === 0) return <>; return (

Margin annotations

{annotations.map((a) => (
{a.target?.selector?.exact && (
{escapeHtml(a.target.selector.exact)}
)} {a.body?.value && (

{escapeHtml(a.body.value)}

)}
{a.creator?.name && ( {a.creator.id ? ( {escapeHtml(a.creator.name)} ) : ( escapeHtml(a.creator.name) )} )} {a.created && ( {formatDate(a.created)} )}
))}

Powered by{" "} Margin

); }