/** * /c/[slug] — Case file reader. * * Renders a single narrated case file from /data/ufo/case/reports/.md. * The reader sees a magazine-style article — title, dateline, body. No * detective attribution, no skeptic framing. */ import { notFound } from "next/navigation"; import { readFile } from "node:fs/promises"; import path from "node:path"; import type { Metadata } from "next"; import { MarkdownBody } from "@/components/markdown-body"; import { AuthBar } from "@/components/auth-bar"; import { BureauNav } from "@/components/bureau-nav"; import { getLocale } from "@/components/locale-toggle"; export const runtime = "nodejs"; export const dynamic = "force-dynamic"; const CASE_ROOT = process.env.CASE_ROOT || "/data/ufo/case"; const SITE_URL = process.env.NEXT_PUBLIC_SITE_URL || "https://disclosure.top"; interface Frontmatter { topic?: string; topic_pt_br?: string; created_at?: string; job_id?: string; } function parseFrontmatter(md: string): { fm: Frontmatter; body: string } { const m = md.match(/^---\n([\s\S]+?)\n---\n([\s\S]*)$/); if (!m) return { fm: {}, body: md }; const fm: Frontmatter = {}; for (const line of m[1].split("\n")) { const kv = line.match(/^([a-z_]+):\s*(.+)$/); if (!kv) continue; let v = kv[2].trim(); if (v.startsWith('"') && v.endsWith('"')) v = v.slice(1, -1); (fm as Record)[kv[1]] = v; } return { fm, body: m[2] }; } async function loadCase(slug: string): Promise<{ fm: Frontmatter; body: string } | null> { try { const md = await readFile(path.join(CASE_ROOT, "reports", `${slug}.md`), "utf-8"); return parseFrontmatter(md); } catch { return null; } } async function hasIllustration(slug: string): Promise { const fs = await import("node:fs/promises"); const UFO_ROOT = process.env.UFO_ROOT || "/data/ufo"; try { await fs.stat(path.join(UFO_ROOT, "processing", "case-art", `${slug}.png`)); return true; } catch { return false; } } /** * Extract the first prose paragraph from the body for the meta description * + OG. We pick the locale-preferred sub-section's opener. */ function pickLead(body: string, locale: "pt-br" | "en"): string { const marker = locale === "pt-br" ? "(PT-BR)" : "(EN)"; const idx = body.indexOf(marker); const slice = idx >= 0 ? body.slice(idx) : body; const m = slice.match(/\n\n([^\n#>|`-][^\n]+(?:\n[^\n#>|`-][^\n]+)*)/); return (m?.[1] ?? "").replace(/\s+/g, " ").trim(); } export async function generateMetadata( { params }: { params: Promise<{ slug: string }> }, ): Promise { const { slug } = await params; const locale = (await getLocale()) === "en" ? "en" : "pt-br"; const c = await loadCase(slug); if (!c) return { title: "Case file not found" }; const title = locale === "pt-br" ? (c.fm.topic_pt_br ?? c.fm.topic ?? slug) : (c.fm.topic ?? slug); const desc = pickLead(c.body, locale).slice(0, 200); const canonical = `${SITE_URL}/c/${slug}`; // OG image — use the case's editorial illustration when present. WhatsApp, // Twitter, Slack, Telegram, ChatGPT search all pull this as the link card. const ogImage = (await hasIllustration(slug)) ? `${SITE_URL}/api/static/processing/case-art/${slug}.png` : `${SITE_URL}/api/static/processing/case-art/green-fireballs-narrative.png`; return { title, description: desc, alternates: { canonical, languages: { "pt-BR": canonical, "en-US": canonical } }, openGraph: { type: "article", title, description: desc, url: canonical, siteName: "The Disclosure Bureau", locale: locale === "pt-br" ? "pt_BR" : "en_US", publishedTime: c.fm.created_at, images: [{ url: ogImage, width: 2000, height: 1125, alt: title }], }, twitter: { card: "summary_large_image", title, description: desc, images: [ogImage], }, }; } export default async function CaseReportPage({ params, }: { params: Promise<{ slug: string }> }) { const { slug } = await params; if (!/^[a-z0-9][a-z0-9-]*$/.test(slug)) notFound(); const locale = (await getLocale()) === "en" ? "en" : "pt-br"; const c = await loadCase(slug); if (!c) notFound(); const { fm, body } = c; const title = locale === "pt-br" ? (fm.topic_pt_br ?? fm.topic ?? slug) : (fm.topic ?? slug); const dateLabel = fm.created_at ? new Date(fm.created_at).toLocaleDateString(locale === "pt-br" ? "pt-BR" : "en-US", { day: "numeric", month: "long", year: "numeric" }) : null; const canonical = `${SITE_URL}/c/${slug}`; const lead = pickLead(body, locale).slice(0, 280); const heroArt = (await hasIllustration(slug)) ? `/api/static/processing/case-art/${slug}.png` : null; return (
32 ? title.slice(0, 32) + "…" : title }, ]} /> {/* Full-bleed editorial hero — only when a painterly illustration exists for this case. Other cases get the plain title header. */} {heroArt && (
{/* eslint-disable-next-line @next/next/no-img-element */} {title}
{locale === "en" ? "Declassified case file" : "Arquivo desclassificado"} {dateLabel && <> · {dateLabel}}

{title}

{locale === "en" ? "Editorial illustration" : "Ilustração editorial"}
)}
{!heroArt && (
{locale === "en" ? "Declassified case file" : "Arquivo desclassificado"} {dateLabel && <> · {dateLabel}}

{title}

)} {lead && (

{lead}

)}
{body}
{/* JSON-LD Article — helps Google + AI crawlers parse the case as a citation-bearing piece of journalism */}