Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 797704fbd0a4a0dcaf9a06ed2353a02ce193f927
parent 0d610c7957768292d5b5e23022bf8465e5e21691
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Sun, 11 Oct 2026 14:22:34 -0400

Merge r26/renderer A1 (f904526b: the report renderer shared in common, parameterised by base) into r26/integration

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Acommon/components/report/MomentArticle.tsx | 196+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acommon/components/report/ReportArticle.tsx | 549+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acommon/components/report/ReportHistory.tsx | 154+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acommon/components/report/ReportIndex.tsx | 61+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acommon/components/report/parts.tsx | 159+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acommon/components/report/renderer.test.ts | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acommon/lib/report/reader-server.test.ts | 130+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acommon/lib/report/reader-server.ts | 145+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcommon/lib/report/revisions.ts | 15++++++++-------
Acommon/lib/report/routes.ts | 32++++++++++++++++++++++++++++++++
Mcommon/lib/report/views.ts | 57++++++++++++++++++++++++++++++++++++++++-----------------
Mexport/app/(workspace)/ask/page.tsx | 2+-
Mexport/app/(workspace)/page.tsx | 8++++----
Aexport/app/components/NotOnCitedSite.tsx | 21+++++++++++++++++++++
Dexport/app/components/reports/MomentArticle.tsx | 180-------------------------------------------------------------------------------
Dexport/app/components/reports/ReportArticle.tsx | 538-------------------------------------------------------------------------------
Dexport/app/components/reports/ReportHistory.tsx | 146-------------------------------------------------------------------------------
Dexport/app/components/reports/ReportIndex.tsx | 58----------------------------------------------------------
Dexport/app/components/reports/parts.tsx | 178-------------------------------------------------------------------------------
Mexport/app/downloads/page.tsx | 2+-
Mexport/app/duplicates/page.tsx | 2+-
Mexport/app/lib/reportSize.test.ts | 2+-
Mexport/app/lib/reports.test.ts | 2+-
Mexport/app/lib/reports.ts | 128+++++++++++--------------------------------------------------------------------
Mexport/app/m/[...moment]/page.tsx | 4++--
Mexport/app/offline/page.tsx | 2+-
Mexport/app/reports/[reportId]/history/page.tsx | 8++++----
Mexport/app/reports/[reportId]/page.tsx | 8++++----
Mexport/app/reports/page.tsx | 4++--
29 files changed, 1602 insertions(+), 1256 deletions(-)

diff --git a/common/components/report/MomentArticle.tsx b/common/components/report/MomentArticle.tsx @@ -0,0 +1,196 @@ +import { VerificationBadge } from "../citations/VerificationBadge"; +import { VerdictChip } from "./VerdictChip"; +import { formatTimestamp } from "../../lib/vtt"; +import { CITATION_KIND_LABELS, spanLabel, type MomentPageView, type RecordView } from "../../lib/report/views"; +import { ExternalLinkText, Eyebrow, dateLabel, textLink } from "./parts"; + +// ONE CITED MOMENT, from its view (common/lib/report/views.ts): a span's +// self-hosted evidence clip (video, or audio with its poster) or a post's +// captured shot and text; the quote and what checking it found; the transcript +// lines around the span; the record's metadata and a link to the original at +// its time (and into the corpus on a full site); and every place on the site +// that cites it. +// +// "Open in the archive" is the corpus link resolver's: by default the view's +// own `corpusUrl` (compose resolved it into the site's own corpus); a build +// that links elsewhere — or nowhere — passes `corpusHref`. + +// The corpus link of a moment's record: a URL, or undefined for none. +export type CorpusHrefResolver = (record: RecordView, view: MomentPageView) => string | undefined; + +const viewCorpusHref: CorpusHrefResolver = (record) => record.corpusUrl; + +export default function MomentArticle({ + view, + corpusHref = viewCorpusHref, +}: { + view: MomentPageView; + corpusHref?: CorpusHrefResolver; +}) { + const r = view.record; + const corpusUrl = corpusHref(r, view); + const isSpan = view.kind === "video" || view.kind === "audio"; + const span = isSpan && view.start !== undefined && view.end !== undefined ? spanLabel(view.start, view.end) : null; + const meta = [r.channelTitle ?? r.channel, dateLabel(view.date ?? r.date), span].filter(Boolean).join(" · "); + const title = r.title ?? (view.kind === "post" ? (view.post?.author ?? r.channelTitle ?? r.channel) : `${r.channel}/${r.id}`); + const clip = view.clip; + const padded = + clip && view.start !== undefined && view.end !== undefined && (clip.start < view.start || clip.end > view.end); + + return ( + <article data-moment={view.key} data-moment-kind={view.kind} className="mx-auto flex w-full max-w-3xl flex-col gap-6"> + <header className="flex flex-col gap-2"> + <Eyebrow>Cited {CITATION_KIND_LABELS[view.kind].toLowerCase()}</Eyebrow> + <h1 className="font-display text-2xl font-semibold leading-tight tracking-tight text-foreground sm:text-3xl"> + {title} + </h1> + {meta && <p className="font-mono text-xs text-muted-foreground">{meta}</p>} + </header> + + {clip && view.kind === "video" && ( + <video + data-evidence-clip="" + controls + playsInline + preload="metadata" + poster={clip.poster} + src={clip.src} + className="aspect-video w-full rounded-lg border border-border bg-black" + /> + )} + {clip && view.kind === "audio" && ( + <div className="flex flex-col gap-3"> + {clip.poster && ( + // eslint-disable-next-line @next/next/no-img-element -- a published file of unknown size; the export serves images unoptimized + <img src={clip.poster} alt="" className="aspect-video w-full rounded-lg border border-border object-cover" /> + )} + <audio data-evidence-clip="" controls preload="metadata" src={clip.src} className="w-full" /> + </div> + )} + {clip && padded && ( + <p className="-mt-3 text-xs text-muted-foreground"> + The clip runs {spanLabel(clip.start, clip.end)}, a little either side of the cited {span} for context. + </p> + )} + {view.post?.shot && ( + // eslint-disable-next-line @next/next/no-img-element -- a published file of unknown size; the export serves images unoptimized + <img + src={view.post.shot} + alt={`Screenshot of the post${view.post.author ? ` by ${view.post.author}` : ""}`} + className="w-full max-w-xl rounded-lg border border-border" + /> + )} + + <div className="flex flex-col gap-2"> + <blockquote className="border-l-4 border-brand pl-4 text-lg leading-relaxed text-foreground"> + {view.speaker && <span className="font-medium text-muted-foreground">{view.speaker}: </span>} + <q className="italic">{view.quote}</q> + </blockquote> + <VerificationBadge verification={view.verification} /> + </div> + + {view.post && view.post.text.trim() !== view.quote.trim() && ( + <div className="flex flex-col gap-1"> + <p className="font-mono text-[10px] uppercase tracking-[0.16em] text-muted-foreground">The post</p> + <p className="whitespace-pre-line text-sm leading-relaxed text-foreground">{view.post.text}</p> + </div> + )} + {view.post?.media && view.post.media.length > 0 && ( + <ul className="flex flex-col gap-3"> + {view.post.media.map((m) => + m.kind === "image" ? ( + <li key={m.src}> + {/* eslint-disable-next-line @next/next/no-img-element -- a published file of unknown size; the export serves images unoptimized */} + <img src={m.src} alt="" className="max-w-full rounded-md border border-border" /> + </li> + ) : ( + <li key={m.src}> + <video src={m.src} controls playsInline preload="metadata" className="w-full rounded-md border border-border" /> + </li> + ), + )} + </ul> + )} + + {view.cues && view.cues.length > 0 && ( + <section aria-labelledby="cues-heading" className="flex flex-col gap-2"> + <h2 id="cues-heading" className="font-mono text-[10px] uppercase tracking-[0.16em] text-muted-foreground"> + Transcript + </h2> + <ol data-cue-lines="" className="flex flex-col rounded-lg border border-border bg-card text-sm"> + {view.cues.map((c, i) => ( + <li + key={`${c.start}-${i}`} + data-in-span={c.inSpan ? "" : undefined} + className={ + c.inSpan + ? "flex gap-3 bg-brand-soft px-3 py-1.5 text-foreground" + : "flex gap-3 px-3 py-1.5 text-muted-foreground" + } + > + <span className="w-14 shrink-0 font-mono text-xs leading-6 tabular-nums">{formatTimestamp(c.start)}</span> + <span className="leading-6">{c.text}</span> + </li> + ))} + </ol> + </section> + )} + + {(r.originalUrl || corpusUrl) && ( + <p className="flex flex-wrap gap-x-4 gap-y-1 text-sm"> + {r.originalUrl && ( + <ExternalLinkText href={r.originalUrl}> + {isSpan && view.start !== undefined + ? `${r.originalLabel ?? "Original"} at ${formatTimestamp(view.start)}` + : "Original post"} + </ExternalLinkText> + )} + {r.downloads?.map((d) => ( + <ExternalLinkText key={d.url} href={d.url}> + {d.label} + </ExternalLinkText> + ))} + {corpusUrl && ( + <a href={corpusUrl} className={textLink}> + Open in the archive + </a> + )} + </p> + )} + + {view.citedIn.length > 0 && ( + <section aria-labelledby="cited-in-heading" className="flex flex-col gap-2 border-t border-border pt-5"> + <h2 id="cited-in-heading" className="font-display text-xl font-semibold text-foreground"> + Cited in + </h2> + <ul data-cited-in="" className="flex flex-col gap-2"> + {view.citedIn.map((e) => ( + <li + key={`${e.reportId}/${e.sectionId}/${e.claimId}/${e.entryId ?? ""}/${e.citationId}`} + className="flex flex-col gap-1 rounded-lg border border-border bg-card p-3 text-sm" + > + <a href={e.href} className={`font-medium ${textLink}`}> + {e.reportTitle} + </a> + <div className="flex flex-wrap items-center gap-2 text-muted-foreground"> + {e.verdict && e.verdictStyle && <VerdictChip verdict={e.verdict} style={e.verdictStyle} />} + {e.sectionTitle ? ( + <span>{e.sectionTitle}</span> + ) : e.entryId ? ( + <span>Timeline{e.entryTitle ? ` — ${e.entryTitle}` : ""}</span> + ) : ( + !e.sectionId && <span>Summary</span> + )} + {(e.claimTitle ?? e.claimText) && ( + <span className="text-foreground">— {e.claimTitle ?? e.claimText}</span> + )} + {e.number !== undefined && <span className="font-mono text-xs">[{e.number}]</span>} + </div> + </li> + ))} + </ul> + </section> + )} + </article> + ); +} diff --git a/common/components/report/ReportArticle.tsx b/common/components/report/ReportArticle.tsx @@ -0,0 +1,549 @@ +import { ArrowDownToLine, Rss } from "lucide-react"; +import { AddedMark, CitationCard } from "../citations/CitationCard"; +import { CitationsProvider } from "../citations/CitationsContext"; +import { CitedMarkdown } from "../citations/CitedMarkdown"; +import { ReferenceList } from "../citations/ReferenceList"; +import { VerdictChip, VerdictTally } from "./VerdictChip"; +import { ReportReader } from "./slides/ReportReader"; +import { REPORT_PAGE_ANCHOR_IDS } from "../../lib/report/slideRules"; +import { hasSlides } from "../../lib/report/slides"; +import type { SourceArchive } from "../../lib/citations/schema"; +import { SITE_REPORTS_BASE, type ReportBase } from "../../lib/report/routes"; +import { + entryDateLabel, + foundGroups, + orderedCitations, + reportDateParts, + reportRevisionLabel, + reportViewPath, + sourceAnchor, + verdictTally, + type CitationView, + type ClaimView, + type EntryView, + type ReportPageView, + type SourceCitationView, +} from "../../lib/report/views"; +import { ArchiveList, ReportName, SourceBlock, SubjectCard, textLink } from "./parts"; + +// ONE REPORT, from its view (common/lib/report/views.ts): the header (its +// series and its title, or the title alone; one line of dates and the +// revision, linked to its history; the document under review as a card on its +// colour's rail, with its archive links; the subtitle), the three tiers each +// opened by a depth marker — the quick take (a fact-check's tally, the +// summary), the timeline when the report keeps one (dated entries, newest +// first, each its own anchor), what the check found, and every claim with its evidence: each +// claim its verdict and flag, the document's own sentence (its still), the +// findings with their inline citations, and the evidence cards (what the +// report added first, marked; what the document gave itself folded away +// last) — then the numbered reference list the inline markers jump to, and +// the downloads: the report as files (HTML, PDF, Markdown, the evidence pack) +// and its citations as data. +// +// A report with a timeline on a site with a public URL publishes feeds of it +// (common/lib/report/feeds.ts): the header links them ("Subscribe"), and the +// page's metadata names them (lib/report/reader-server.ts reportMetadata). +// +// Every href on the page is the view's own (compose resolved them under the +// build's base) but one: the view switch fetches page.json, under `base` +// (lib/report/routes.ts). +// +// ONE ARTICLE, THREE SHAPES (release 22): the view switch (Article | Slides | +// Overview — common/components/report/slides/ReportReader) follows the +// header and sticks under the site's header while the article scrolls, so a +// switch keeps the place the reader is at; every anchor in the article lands +// below the two bars (`scroll-mt-32`: the site header's 57 px and the +// switch's 54). Every place a slide stands for has its id here: the header, the quick +// take, what the check found, each section and claim, and the end matter +// (lib/report/slideRules.ts REPORT_PAGE_ANCHOR_IDS). The article itself stays +// this static page; the other views are built in the browser from page.json. + +const proseClass = "text-[0.95rem] leading-relaxed text-foreground"; + +const DOWNLOADS: readonly (readonly [keyof NonNullable<ReportPageView["downloads"]>, string])[] = [ + ["html", "HTML"], + ["pdf", "PDF"], + ["md", "Markdown"], + ["slides", "Slides"], + ["slides-pdf", "Slides PDF"], + ["zip", "Evidence pack"], + ["json", "Citations JSON"], + ["csv", "CSV"], +]; + +// A claim's sentence in a quoted document: its still (or its words), on a rail +// in the document's colour (its `accent`, else the border colour) — the same +// colour as the document's box, so the sentences and the box read as one +// source. A sentence of the document under review needs no link to it: the +// rail says whose it is. Another document's sentence links to its box. +function SourceSentence({ + c, + archives, + isSubject, +}: { + c: SourceCitationView; + archives: readonly SourceArchive[] | undefined; + isSubject: boolean; +}) { + const hasArchives = !!archives && archives.length > 0; + return ( + <figure + data-source-sentence={c.id} + className={`flex flex-col gap-1.5 border-l-4 pl-3${c.sourceAccent ? "" : " border-border"}`} + style={c.sourceAccent ? { borderLeftColor: c.sourceAccent } : undefined} + > + {c.image ? ( + // eslint-disable-next-line @next/next/no-img-element -- a published file of unknown size; the export serves images unoptimized + <img + src={c.image} + alt={c.quote} + loading="lazy" + className="w-full max-w-xl rounded-md border border-border bg-white object-contain object-left-top" + /> + ) : ( + <blockquote className="italic text-muted-foreground"> + <q>{c.quote}</q> + </blockquote> + )} + {(!isSubject || hasArchives) && ( + <figcaption className="flex flex-col gap-1 text-xs text-muted-foreground"> + {!isSubject && ( + <a href={`#${sourceAnchor(c.sourceId)}`} className={textLink}> + from {c.sourceTitle} + </a> + )} + {/* Only the document's archive links that sit in this sentence; the + full list is with the document, once. */} + {hasArchives && <ArchiveList archives={archives} />} + </figcaption> + )} + </figure> + ); +} + +// A claim's flag: a quiet pill in the accent, behind the project's mark (the +// mark added evidence wears: the two read as the report's own marks). +function FlagPill({ flag, className }: { flag: string; className?: string }) { + return ( + <span + data-claim-flag="" + className={`inline-flex shrink-0 items-center gap-1.5 rounded-full border border-brand/40 bg-brand-soft px-2.5 py-0.5 text-xs font-medium text-brand${className ? ` ${className}` : ""}`} + > + <AddedMark className="size-3" /> + {flag} + </span> + ); +} + +// Where a tier of the page begins: a hairline with, at its left, how deep it +// goes (one, two or three dots filled in the accent). Decoration only: the +// tier's own label or heading names it. +function TierMarker({ depth }: { depth: 1 | 2 | 3 }) { + return ( + <div data-tier-marker={depth} aria-hidden="true" className="flex items-center gap-2.5"> + <span className="flex items-center gap-1"> + {[1, 2, 3].map((i) => ( + <span + key={i} + data-depth-dot={i <= depth ? "filled" : "empty"} + className={ + i <= depth + ? "size-1.5 rounded-full bg-brand" + : "size-1.5 rounded-full border border-muted-foreground/60" + } + /> + ))} + </span> + <span className="h-px flex-1 bg-border" /> + </div> + ); +} + +// A timeline entry: its date first and largest (what a timeline is read by), +// linking to its own anchor, then its title and its body. A dot on the +// timeline's rail marks it. +function Entry({ entry }: { entry: EntryView }) { + return ( + <li id={entry.id} data-entry={entry.id} className="relative flex scroll-mt-20 flex-col gap-1.5"> + <span + aria-hidden="true" + className="absolute top-[0.45rem] -left-[calc(1rem+4.5px)] size-2 rounded-full bg-brand ring-4 ring-background sm:-left-[calc(1.25rem+4.5px)]" + /> + <p className="flex flex-wrap items-baseline gap-x-2 font-mono text-sm"> + <a href={`#${entry.id}`} data-entry-date="" className="font-semibold text-brand hover:underline"> + <time dateTime={entry.date}>{entryDateLabel(entry.date)}</time> + </a> + {entry.updated && ( + <span className="text-xs text-muted-foreground"> + updated <time dateTime={entry.updated}>{entryDateLabel(entry.updated)}</time> + </span> + )} + </p> + <h3 className="font-display text-lg font-semibold leading-snug text-foreground">{entry.title}</h3> + <CitedMarkdown className={proseClass}> + {entry.body} + </CitedMarkdown> + </li> + ); +} + +// A claim: its verdict, flag and title; the document's own sentence (its +// still, else its verbatim words) when the claim cites one, else the claim as +// the report states it, plain; the findings; the evidence. +function Claim({ + claim, + view, + subjectNoun, +}: { + claim: ClaimView; + view: ReportPageView; + // What the document under review is called: "article" or "source". + subjectNoun: string; +}) { + const cited = claim.sourceQuote ? view.citations[claim.sourceQuote] : undefined; + const sentence = cited?.kind === "source" ? cited : undefined; + const evidence = claim.citations + .filter((id) => id !== claim.sourceQuote) + .map((id) => view.citations[id]) + .filter((c): c is CitationView => !!c); + // What the report adds comes first, marked; then evidence of unknown origin; + // what the document under review gave itself is folded away at the end. + const added = evidence.filter((c) => c.origin === "added"); + const unknown = evidence.filter((c) => c.origin === undefined); + const given = evidence.filter((c) => c.origin === "subject"); + const shown = [...added, ...unknown]; + const addedLabel = `Not in the ${subjectNoun}`; + return ( + <article + id={claim.id} + data-claim={claim.id} + className="flex scroll-mt-20 flex-col gap-3 rounded-lg border border-border bg-surface p-4 sm:p-5" + > + <div className="flex flex-wrap items-start gap-x-3 gap-y-2"> + {claim.verdict && <VerdictChip verdict={claim.verdict} style={view.verdicts[claim.verdict]} className="mt-0.5" />} + {claim.flag && <FlagPill flag={claim.flag} className="mt-0.5" />} + <h3 className="min-w-0 flex-1 basis-60 font-display text-lg font-semibold leading-snug text-foreground"> + <a href={`#${claim.id}`} className="hover:text-brand transition-colors"> + {claim.title ?? claim.text} + </a> + </h3> + </div> + {sentence ? ( + <SourceSentence c={sentence} archives={claim.archives} isSubject={sentence.sourceId === view.subject} /> + ) : ( + claim.title && ( + <p data-claim-text="" className="text-sm text-muted-foreground"> + {claim.text} + </p> + ) + )} + {claim.findings && ( + <CitedMarkdown className={proseClass}> + {claim.findings} + </CitedMarkdown> + )} + {evidence.length > 0 && ( + <div className="flex flex-col gap-2"> + <p className="font-mono text-[10px] uppercase tracking-[0.16em] text-muted-foreground">Evidence</p> + {shown.length > 0 && ( + <div className="grid gap-3 sm:grid-cols-2"> + {shown.map((c) => ( + <CitationCard key={c.id} citation={c} addedLabel={addedLabel} /> + ))} + </div> + )} + {given.length > 0 && ( + <details data-subject-evidence="" className="group"> + <summary className="cursor-pointer select-none font-mono text-xs text-muted-foreground hover:text-foreground"> + {`In the ${subjectNoun} (${given.length})`} + </summary> + <div className="mt-2 grid gap-3 sm:grid-cols-2"> + {given.map((c) => ( + <CitationCard key={c.id} citation={c} addedLabel={addedLabel} /> + ))} + </div> + </details> + )} + </div> + )} + </article> + ); +} + +export default function ReportArticle({ + view, + base = SITE_REPORTS_BASE, +}: { + view: ReportPageView; + base?: ReportBase; +}) { + const isFactcheck = view.kind === "factcheck"; + const tally = isFactcheck ? verdictTally(view) : []; + const references = orderedCitations(view); + const subject = view.subject ? view.sources[view.subject] : undefined; + const subjectNoun = subject?.kind === "article" ? "article" : "source"; + const dates = reportDateParts(view); + const claimCount = view.sections.reduce((n, s) => n + s.claims.length, 0); + // The report as files (its exports), then its citations as data: only what + // compose published. + const downloads = DOWNLOADS.flatMap(([key, label]) => { + const href = view.downloads?.[key]; + return href ? [[key, label, href] as const] : []; + }); + const groups = isFactcheck ? foundGroups(view) : []; + const slides = hasSlides(view); + const jumps = [ + ...(groups.length > 0 ? [{ href: "#found", label: "What the check found" }] : []), + { href: "#claims", label: "Every claim" }, + ...(downloads.length > 0 ? [{ href: "#downloads", label: "Downloads" }] : []), + ]; + // Documents quoted that are not the subject, each shown once before the + // references. + const otherSources = Object.values(view.sources).filter((s) => s.id !== view.subject); + + return ( + // One citation map for every inline marker on the page (CitationsContext): + // serialized once, not once per marker. + <CitationsProvider citations={view.citations}> + <article + data-report={view.id} + className={`mx-auto flex w-full max-w-3xl flex-col gap-8${slides ? " [&_[id]]:scroll-mt-32" : ""}`} + > + {/* The report's name (its series on one line, its title on the next; + without a series, the title alone), one line of dates and the + revision, the document under review, the subtitle. */} + <header id={REPORT_PAGE_ANCHOR_IDS.head} className="flex scroll-mt-20 flex-col gap-3"> + <h1 className="font-display text-3xl font-semibold leading-tight tracking-tight text-foreground [overflow-wrap:anywhere] sm:text-4xl"> + <ReportName series={view.series} title={view.title} /> + </h1> + {(dates.length > 0 || view.history) && ( + <p data-report-dates="" className="font-mono text-xs text-muted-foreground"> + {dates.join(" · ")} + {view.history && ( + <> + {dates.length > 0 ? " · " : null} + <a href={view.history.href} data-report-revision={view.history.revision} + className="underline decoration-muted-foreground/40 underline-offset-2 hover:text-foreground hover:decoration-foreground" + > + {reportRevisionLabel(view.history.revision, view.history.current)} + </a> + </> + )} + </p> + )} + {view.feeds && ( + <p data-report-feeds="" className="flex items-center gap-1.5 font-mono text-xs text-muted-foreground"> + <Rss className="size-3.5" aria-hidden /> + Subscribe: + <a href={view.feeds.rss} type="application/rss+xml" data-feed="rss" className={textLink}> + RSS + </a> + <span aria-hidden="true">·</span> + <a href={view.feeds.json} type="application/feed+json" data-feed="json" className={textLink}> + JSON + </a> + </p> + )} + {subject && <SubjectCard source={subject} />} + {view.subtitle && <p className="text-lg text-muted-foreground">{view.subtitle}</p>} + </header> + + {/* The view switch: sticky just under the site's header (Header.tsx, + `sticky top-0`, 56 px and its border), within the article's box. */} + {slides && ( + <div data-report-views="" className="sticky top-14 z-10 flex items-center bg-background/80 py-2 backdrop-blur-md"> + <ReportReader pagePath={reportViewPath(view.id, base)} title={view.title} series={view.series} /> + </div> + )} + + {/* The report as a video, when it has one. */} + {view.video && ( + <figure data-report-video="" className="flex flex-col gap-2"> + <video + controls + playsInline + preload="metadata" + poster={view.video.poster} + src={view.video.src} + className="aspect-video w-full rounded-lg border border-border bg-black" + /> + {view.video.caption && ( + <figcaption className="text-sm text-muted-foreground">{view.video.caption}</figcaption> + )} + </figure> + )} + + {/* The quick take: the tally and the summary, then where to go next. */} + <section + id={REPORT_PAGE_ANCHOR_IDS.summary} + data-report-tier="1" + aria-label="In brief" + className="flex scroll-mt-20 flex-col gap-4" + > + <TierMarker depth={1} /> + {tally.length > 0 && ( + <div className="flex flex-col gap-2"> + <p className="font-mono text-[10px] uppercase tracking-[0.16em] text-muted-foreground"> + {claimCount} claim{claimCount === 1 ? "" : "s"} checked + </p> + <VerdictTally tally={tally} styles={view.verdicts} /> + </div> + )} + {view.summary && ( + <CitedMarkdown className={proseClass}> + {view.summary} + </CitedMarkdown> + )} + <p data-report-jumps="" className="flex flex-wrap gap-x-2 gap-y-1 text-sm"> + {jumps.map((j, i) => ( + <span key={j.href} className="whitespace-nowrap"> + {i > 0 && <span aria-hidden="true" className="mr-2 text-muted-foreground">·</span>} + <a href={j.href} className={textLink}> + {j.label} + </a> + </span> + ))} + </p> + </section> + + {/* The timeline: dated entries, newest first, on a rail. */} + {view.entries && view.entries.length > 0 && ( + <section data-report-timeline="" aria-labelledby="timeline-heading" className="flex flex-col gap-4"> + <h2 id="timeline-heading" className="font-display text-2xl font-semibold tracking-tight text-foreground"> + Timeline + </h2> + <ol className="ml-1 flex flex-col gap-7 border-l border-border pl-4 sm:pl-5"> + {view.entries.map((e) => ( + <Entry key={e.id} entry={e} /> + ))} + </ol> + </section> + )} + + {/* What the check found: every ruled claim by verdict, one line each. */} + {groups.length > 0 && ( + <section id="found" data-report-tier="2" aria-labelledby="found-heading" className="flex scroll-mt-20 flex-col gap-4"> + <TierMarker depth={2} /> + <h2 id="found-heading" className="font-display text-2xl font-semibold tracking-tight text-foreground"> + What the check found + </h2> + {groups.map((g) => ( + <div key={g.verdict} data-found-group={g.verdict} className="flex flex-col gap-2"> + <h3> + <VerdictChip verdict={g.verdict} style={view.verdicts[g.verdict]} count={g.claims.length} /> + </h3> + <ul className="flex flex-col gap-1.5 pl-1 text-sm"> + {g.claims.map((c) => ( + <li key={c.id} data-found-row={c.id} className="leading-snug"> + <a href={`#${c.id}`} className="font-medium text-foreground hover:text-brand transition-colors"> + {c.title ?? c.text} + </a> + {c.gist && <span className="text-muted-foreground"> — {c.gist}</span>} + {c.flag && ( + <> + {" "} + <FlagPill flag={c.flag} className="ml-1 align-middle" /> + </> + )} + </li> + ))} + </ul> + </div> + ))} + </section> + )} + + {/* Every claim, with its evidence. */} + <div id="claims" data-report-tier="3" className="flex scroll-mt-20 flex-col gap-8"> + <div className="flex flex-col gap-4"> + <TierMarker depth={3} /> + <h2 className="font-display text-2xl font-semibold tracking-tight text-foreground"> + Every claim, with its evidence + </h2> + {view.method && ( + <div data-report-method="" className="flex flex-col gap-1"> + <h3 className="font-mono text-xs uppercase tracking-[0.16em] text-muted-foreground">How it was checked</h3> + <CitedMarkdown className={proseClass}> + {view.method} + </CitedMarkdown> + </div> + )} + </div> + + {view.sections.length > 1 && ( + <nav aria-label="Sections" className="rounded-lg border border-border p-4 text-sm"> + <ol className="flex list-decimal flex-col gap-1 pl-5 marker:text-muted-foreground"> + {view.sections.map((s) => ( + <li key={s.id}> + <a href={`#${s.id}`} className={textLink}> + {s.title} + </a> + {s.claims.length > 0 && ( + <span className="ml-2 font-mono text-xs text-muted-foreground"> + {s.claims.length} claim{s.claims.length === 1 ? "" : "s"} + </span> + )} + </li> + ))} + </ol> + </nav> + )} + + {view.sections.map((s) => ( + <section key={s.id} id={s.id} data-section={s.id} className="flex scroll-mt-20 flex-col gap-4"> + <h2 className="font-display text-2xl font-semibold tracking-tight text-foreground">{s.title}</h2> + {s.body && ( + <CitedMarkdown className={proseClass}> + {s.body} + </CitedMarkdown> + )} + {s.claims.map((c) => ( + <Claim key={c.id} claim={c} view={view} subjectNoun={subjectNoun} /> + ))} + </section> + ))} + </div> + + {/* The end matter: the documents quoted, the references, the + downloads — the sources slide's place. */} + <div id={REPORT_PAGE_ANCHOR_IDS.end} className="flex scroll-mt-20 flex-col gap-8 empty:hidden"> + {otherSources.length > 0 && ( + <section aria-labelledby="sources-heading" className="flex flex-col gap-3 border-t border-border pt-6"> + <h2 id="sources-heading" className="font-display text-2xl font-semibold tracking-tight text-foreground"> + Sources + </h2> + {otherSources.map((s) => ( + <SourceBlock key={s.id} source={s} label="Quoted" /> + ))} + </section> + )} + + {references.length > 0 && ( + <section id="references" aria-labelledby="references-heading" className="flex scroll-mt-20 flex-col gap-2 border-t border-border pt-6"> + <h2 id="references-heading" className="font-display text-2xl font-semibold tracking-tight text-foreground"> + References + </h2> + <ReferenceList citations={references} addedLabel={`Not in the ${subjectNoun}`} /> + </section> + )} + + {downloads.length > 0 && ( + <p + id="downloads" + data-citation-downloads="" + className="flex scroll-mt-20 flex-wrap items-center gap-x-3 gap-y-1 text-sm text-muted-foreground" + > + <ArrowDownToLine className="size-4" aria-hidden /> + Download: + {downloads.map(([key, label, href]) => ( + <a key={key} href={href} download data-download={key} className={textLink}> + {label} + </a> + ))} + </p> + )} + </div> + </article> + </CitationsProvider> + ); +} diff --git a/common/components/report/ReportHistory.tsx b/common/components/report/ReportHistory.tsx @@ -0,0 +1,154 @@ +import { + reportHistoryViewPath, + type ClaimChange, + type ClaimDiffField, + type DiffSegment, + type ReportHistoryView, + type ReportRevisionView, +} from "../../lib/report/revisions"; +import { SITE_REPORTS_BASE, type ReportBase } from "../../lib/report/routes"; +import { reportPagePath } from "../../lib/report/views"; +import { ReportName, textLink } from "./parts"; + +// A REPORT'S REVISION HISTORY, from its history.json (common/lib/report/revisions.ts): +// how to clone it, then every revision, newest first — its number, date, +// commit and report.json sha256 (the hash every export's footer prints), the +// change summary, and each changed claim as an inline word diff against the +// revision before. `base` is where the build serves its reports +// (lib/report/routes.ts): the links back to the report and to history.json. + +const FIELD_LABELS: Record<ClaimDiffField, string> = { + title: "Title", + text: "Claim", + verdict: "Verdict", + findings: "Findings", +}; + +const STATUS_LABELS: Record<ClaimChange["status"], string> = { + added: "added", + removed: "removed", + edited: "edited", +}; + +// `2026-03-08T12:00:00Z` → `2026-03-08 12:00 UTC`. +export function revisionDate(iso: string): string { + const m = /^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2})/.exec(iso); + return m ? `${m[1]} ${m[2]} UTC` : iso; +} + +function Diff({ segments }: { segments: DiffSegment[] }) { + return ( + <> + {segments.map((s, i) => + s.op === "ins" ? ( + <ins key={i} data-diff="ins" className="rounded-sm bg-success-soft text-foreground no-underline decoration-success"> + {s.text} + </ins> + ) : s.op === "del" ? ( + <del key={i} data-diff="del" className="rounded-sm bg-destructive-soft text-muted-foreground decoration-destructive"> + {s.text} + </del> + ) : ( + <span key={i}>{s.text}</span> + ), + )} + </> + ); +} + +function ClaimDiff({ change }: { change: ClaimChange }) { + return ( + <div + data-claim-change={change.id} + data-status={change.status} + className="flex flex-col gap-1.5 rounded-md border border-border bg-card px-3 py-2 text-sm" + > + <p className="font-mono text-[11px] text-muted-foreground"> + <span className="text-foreground">{change.id}</span> · {change.section} · {STATUS_LABELS[change.status]} + </p> + {change.fields.map((f) => ( + <p key={f.field} data-field={f.field} className="whitespace-pre-wrap break-words leading-relaxed"> + <span className="mr-2 font-mono text-[10px] uppercase tracking-[0.14em] text-muted-foreground"> + {FIELD_LABELS[f.field]} + </span> + <Diff segments={f.diff} /> + </p> + ))} + </div> + ); +} + +function Revision({ r }: { r: ReportRevisionView }) { + return ( + <li id={`r${r.revision}`} data-revision={r.revision} className="flex scroll-mt-20 flex-col gap-3 border-t border-border pt-5"> + <div className="flex flex-col gap-1"> + <h2 className="font-display text-xl font-semibold tracking-tight text-foreground">Revision {r.revision}</h2> + <p className="font-mono text-xs text-muted-foreground">{revisionDate(r.date)}</p> + </div> + <dl className="grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 font-mono text-xs"> + <dt className="text-muted-foreground">commit</dt> + <dd data-commit={r.commit} className="break-all text-foreground"> + {r.commit} + </dd> + <dt className="text-muted-foreground">report sha256</dt> + <dd data-report-sha256={r.reportSha256} className="break-all text-foreground"> + {r.reportSha256} + </dd> + </dl> + {r.summary.length > 0 && ( + <ul data-revision-summary="" className="flex list-disc flex-col gap-0.5 pl-5 text-sm text-foreground"> + {r.summary.map((line, i) => ( + <li key={i}>{line}</li> + ))} + </ul> + )} + {r.claims.length > 0 && ( + <div className="flex flex-col gap-2"> + {r.claims.map((c) => ( + <ClaimDiff key={c.id} change={c} /> + ))} + </div> + )} + </li> + ); +} + +export default function ReportHistory({ + view, + base = SITE_REPORTS_BASE, +}: { + view: ReportHistoryView; + base?: ReportBase; +}) { + const revisions = [...view.revisions].reverse(); + return ( + <article data-report-history={view.reportId} className="mx-auto flex w-full max-w-3xl flex-col gap-6"> + <header className="flex flex-col gap-3"> + <p className="text-sm"> + <a href={reportPagePath(view.reportId, base)} className={textLink}> + <ReportName series={view.series} title={view.title} /> + </a> + </p> + <h1 className="font-display text-3xl font-semibold leading-tight tracking-tight text-foreground">Revision history</h1> + <p className="text-sm text-muted-foreground"> + Every edit to this report, newest first. Each revision is a commit in the report&apos;s own git history; its + report sha256 is the hash printed at the foot of the report&apos;s downloads.{" "} + <a href={reportHistoryViewPath(view.reportId, base)} className={textLink}> + history.json + </a> + </p> + <pre + data-history-clone="" + className="overflow-x-auto rounded-md border border-border bg-muted px-3 py-2 font-mono text-xs text-foreground" + > + <code>git clone {view.clone}</code> + </pre> + </header> + <ol className="flex flex-col gap-6"> + {revisions.map((r) => ( + <Revision key={r.revision} r={r} /> + ))} + </ol> + </article> + ); +} diff --git a/common/components/report/ReportIndex.tsx b/common/components/report/ReportIndex.tsx @@ -0,0 +1,61 @@ +import Link from "next/link"; +import type { ReportIndexView } from "../../lib/report/views"; +import { EmptyState, Eyebrow, ReportName, dateLabel } from "./parts"; + +// The report index: `/reports/`, and a cited site's home page when it has more +// than one report. One card per published report, in the site's order +// (site.json `reports`): its name, subtitle and dates -- its counts and tally +// are the report page's. `heading: null` draws no heading (the home page: the +// header already names the site). `empty` is what an index with nothing in it +// says. + +export default function ReportIndex({ + index, + heading = "Reports", + tagline, + empty = { title: "No reports", message: "This site has not published a report yet." }, +}: { + index: ReportIndexView | null; + heading?: string | null; + tagline?: string; + empty?: { title: string; message: string }; +}) { + const reports = index?.reports ?? []; + if (reports.length === 0) { + return <EmptyState title={empty.title}>{empty.message}</EmptyState>; + } + return ( + <div className="mx-auto flex w-full max-w-3xl flex-col gap-6"> + {(heading || tagline) && ( + <header className="flex flex-col gap-1"> + {heading && <h1 className="font-display text-3xl font-semibold tracking-tight text-foreground">{heading}</h1>} + {tagline && <p className="text-sm text-muted-foreground">{tagline}</p>} + </header> + )} + <ul data-report-index="" className="flex flex-col gap-4"> + {reports.map((r) => { + const dates = [ + r.published ? `Published ${dateLabel(r.published)}` : null, + r.updated && r.updated !== r.published ? `updated ${dateLabel(r.updated)}` : null, + ] + .filter(Boolean) + .join(" · "); + return ( + <li key={r.id} data-report-entry={r.id}> + <article className="flex flex-col gap-2 rounded-lg border border-border bg-card p-4 sm:p-5"> + {!r.series && <Eyebrow>{r.kind === "factcheck" ? "Fact-check" : "Report"}</Eyebrow>} + <h2 className="font-display text-xl font-semibold leading-snug text-foreground"> + <Link href={r.href} className="hover:text-brand transition-colors"> + <ReportName series={r.series} title={r.title} /> + </Link> + </h2> + {r.subtitle && <p className="text-sm text-muted-foreground">{r.subtitle}</p>} + {dates && <p className="font-mono text-xs text-muted-foreground">{dates}</p>} + </article> + </li> + ); + })} + </ul> + </div> + ); +} diff --git a/common/components/report/parts.tsx b/common/components/report/parts.tsx @@ -0,0 +1,159 @@ +import { Fragment } from "react"; +import { ExternalLink } from "lucide-react"; +import { sourceAnchor, subjectMetaParts, type SourceView } from "../../lib/report/views"; +import type { SourceArchive } from "../../lib/citations/schema"; + +// Small pieces the report, index and moment pages share — on every build that +// renders reports (common/lib/report/reader-server.ts reads their views). + +// `2026-10-04T12:00:00Z` → `2026-10-04`; a partial date (`2026-10`) as given. +export function dateLabel(v: string | undefined): string | undefined { + if (!v) return undefined; + return /^\d{4}-\d{2}-\d{2}T/.test(v) ? v.slice(0, 10) : v; +} + +export function Eyebrow({ children }: { children: React.ReactNode }) { + return <p className="font-mono text-xs uppercase tracking-[0.18em] text-brand">{children}</p>; +} + +// A report's name as a heading, on its page, in the index and on the history +// page. With a series, the series is its own line in the accent (the tag, +// like a wordmark's lead) and the title the next, in regular weight — both +// inside the heading, so its name reads "<series> <title>"; without one, the +// title alone. +export function ReportName({ series, title }: { series?: string; title: string }) { + if (!series) return <>{title}</>; + return ( + <> + <span data-report-series="" className="block font-semibold text-brand"> + {series} + </span>{" "} + <span className="block font-normal">{title}</span> + </> + ); +} + +export const textLink = + "text-brand underline decoration-brand/40 underline-offset-2 hover:decoration-brand"; + +export function ExternalLinkText({ href, children, title }: { href: string; children: React.ReactNode; title?: string }) { + return ( + <a href={href} target="_blank" rel="noopener noreferrer" title={title} className={`inline-flex items-center gap-1 ${textLink}`}> + {children} + <ExternalLink className="size-3 shrink-0" aria-hidden /> + </a> + ); +} + +// A document a report quotes: its title (linked), byline, note, and its +// archive links in the context the document gave them — collapsed, since a +// long document may carry hundreds. The block is the document's one place on +// the page: its anchor is what a source citation's "from <title>" links to. +// With an `accent`, its left edge wears it, as its sentences' rails do. +export function SourceBlock({ source, label }: { source: SourceView; label: string }) { + const byline = [source.publisher, source.author, dateLabel(source.date)].filter(Boolean).join(" · "); + const n = source.archives.length; + return ( + <div + id={sourceAnchor(source.id)} + data-subject-source={source.id} + className={`flex scroll-mt-20 flex-col gap-1.5 rounded-lg border border-border bg-card p-4 text-sm${source.accent ? " border-l-4" : ""}`} + style={source.accent ? { borderLeftColor: source.accent } : undefined} + > + <p className="font-mono text-[10px] uppercase tracking-[0.16em] text-muted-foreground">{label}</p> + <p className="font-medium leading-snug text-foreground"> + {source.url ? <ExternalLinkText href={source.url}>{source.title}</ExternalLinkText> : source.title} + </p> + {byline && <p className="font-mono text-xs text-muted-foreground">{byline}</p>} + {source.note && <p className="text-xs text-muted-foreground">{source.note}</p>} + {n > 0 && ( + <details data-source-archives={n} className="mt-1 text-xs"> + <summary className="cursor-pointer text-muted-foreground hover:text-foreground"> + {`${n} archive link${n === 1 ? "" : "s"} in context`} + </summary> + <ArchiveList archives={source.archives} className="mt-2" /> + </details> + )} + </div> + ); +} + +// The document under review, under the report's heading: its title linked to +// the document, then "<author> · <publisher> · <date>", then its archive links +// folded away. No label: its left rail, in the document's colour (its +// `accent`, else the border colour) as its sentences' rails below are, says +// whose it is. It is the document's one place on the page, so it carries the +// anchor a citation's "from <title>" links to. +export function SubjectCard({ source }: { source: SourceView }) { + // Each part stays whole on a narrow screen (a date never splits at its dashes). + const meta = subjectMetaParts(source); + const n = source.archives.length; + return ( + <div + id={sourceAnchor(source.id)} + data-subject-source={source.id} + className={`flex min-w-0 scroll-mt-20 flex-col gap-1 rounded-r-md border-l-4 bg-surface py-2.5 pl-3 pr-4 text-sm${source.accent ? "" : " border-border"}`} + style={source.accent ? { borderLeftColor: source.accent } : undefined} + > + <p data-subject-title="" className="font-medium leading-snug text-foreground [overflow-wrap:anywhere]"> + {source.url ? ( + <a + href={source.url} + target="_blank" + rel="noopener noreferrer" + className={`${textLink} after:ml-1 after:inline-block after:text-xs after:content-['↗']`} + > + {source.title} + </a> + ) : ( + source.title + )} + </p> + {meta.length > 0 && ( + <p className="text-xs text-muted-foreground"> + {meta.map((part, i) => ( + <Fragment key={i}> + {i > 0 && " · "} + <span className="whitespace-nowrap">{part}</span> + </Fragment> + ))} + </p> + )} + {n > 0 && ( + <details data-source-archives={n} className="text-xs"> + <summary className="cursor-pointer text-muted-foreground hover:text-foreground"> + {`${n} archive link${n === 1 ? "" : "s"}`} + </summary> + <ArchiveList archives={source.archives} className="mt-2" /> + </details> + )} + </div> + ); +} + +// Archive links, each with the words around it in the document. A document +// may carry hundreds, so a link is text with a CSS arrow, not two inline SVG +// icons apiece. +export function ArchiveList({ archives, className }: { archives: readonly SourceArchive[]; className?: string }) { + return ( + <ul className={`flex flex-col gap-1 ${className ?? ""}`}> + {archives.map((a, i) => ( + <li key={`${i}:${a.url}`} className="flex flex-wrap items-baseline gap-x-2"> + <a href={a.url} target="_blank" rel="noopener noreferrer" className={`${textLink} after:ml-0.5 after:content-['↗']`}> + {a.label} + </a> + {a.context && <span className="text-muted-foreground">— {a.context}</span>} + </li> + ))} + </ul> + ); +} + +export function EmptyState({ title, children }: { title: string; children: React.ReactNode }) { + return ( + <div data-reports-empty="" className="mx-auto flex max-w-2xl flex-col gap-3"> + <h1 className="font-display text-2xl font-semibold text-foreground">{title}</h1> + <p className="text-sm text-muted-foreground">{children}</p> + </div> + ); +} diff --git a/common/components/report/renderer.test.ts b/common/components/report/renderer.test.ts @@ -0,0 +1,67 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import * as React from "react"; +import { renderToStaticMarkup } from "react-dom/server"; +import { REPORT_HISTORY_FORMAT, REPORT_HISTORY_VERSION, type ReportHistoryView } from "../../lib/report/revisions"; +import { MOMENT_PAGE_FORMAT, REPORT_VIEWS_VERSION, type MomentPageView } from "../../lib/report/views"; +import MomentArticle from "./MomentArticle"; +import ReportHistory from "./ReportHistory"; +import ReportIndex from "./ReportIndex"; + +// The shared renderer's parameters (plans/reports-on-homepage.md, A1): the +// base its build serves reports under, the corpus link resolver, and an empty +// index's words. Every default is what a site rendered before they existed. + +(globalThis as { React?: typeof React }).React = React; +const h = React.createElement; + +const history: ReportHistoryView = { + format: REPORT_HISTORY_FORMAT, + version: REPORT_HISTORY_VERSION, + reportId: "demo", + title: "Demo", + branch: "main", + clone: "/reports/demo/history/repo", + revisions: [{ revision: 1, date: "2026-10-01T09:00:00Z", commit: "c".repeat(40), reportSha256: "a".repeat(64), summary: [], claims: [] }], +}; + +const moment: MomentPageView = { + format: MOMENT_PAGE_FORMAT, + version: REPORT_VIEWS_VERSION, + key: "chan/post1", + kind: "post", + record: { channel: "chan", id: "post1", originalUrl: "https://example.org/p/1", corpusUrl: "/?v=chan%2Fpost1&vm=post" }, + quote: "A quote.", + citedIn: [], +}; + +test("a history page links its report and its history.json under the site's base, or the one it is given", () => { + const site = renderToStaticMarkup(h(ReportHistory, { view: history })); + assert.match(site, /href="\/reports\/demo\/"/); + assert.match(site, /href="\/reports\/demo\/history\/history.json"/); + const other = renderToStaticMarkup(h(ReportHistory, { view: history, base: "/articles/" })); + assert.match(other, /href="\/articles\/demo\/"/); + assert.match(other, /href="\/articles\/demo\/history\/history.json"/); + assert.doesNotMatch(other, /href="\/reports\//); +}); + +test("a moment opens in the archive at the view's corpus link, or the resolver's, or nowhere", () => { + const own = renderToStaticMarkup(h(MomentArticle, { view: moment })); + assert.match(own, /href="\/\?v=chan%2Fpost1&amp;vm=post"[^>]*>Open in the archive/); + const elsewhere = renderToStaticMarkup( + h(MomentArticle, { view: moment, corpusHref: (r) => `https://archive.example.org/?v=${r.channel}%2F${r.id}` }), + ); + assert.match(elsewhere, /href="https:\/\/archive.example.org\/\?v=chan%2Fpost1"[^>]*>Open in the archive/); + const none = renderToStaticMarkup(h(MomentArticle, { view: moment, corpusHref: () => undefined })); + assert.doesNotMatch(none, /Open in the archive/); + assert.match(none, /Original post/); +}); + +test("an empty index says the site's words, or the ones it is given", () => { + assert.match(renderToStaticMarkup(h(ReportIndex, { index: null })), /This site has not published a report yet/); + const other = renderToStaticMarkup( + h(ReportIndex, { index: null, empty: { title: "No articles", message: "Nothing published yet." } }), + ); + assert.match(other, /No articles/); + assert.match(other, /Nothing published yet\./); +}); diff --git a/common/lib/report/reader-server.test.ts b/common/lib/report/reader-server.test.ts @@ -0,0 +1,130 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; +import { createReportReader, reportMetadata } from "./reader-server"; +import { isReportBase, reportBaseDir, SITE_REPORTS_BASE } from "./routes"; +import { reportHistoryPagePath, reportHistoryViewPath, REPORT_HISTORY_FORMAT } from "./revisions"; +import { + MOMENT_INDEX_FORMAT, + MOMENT_PAGE_FORMAT, + MOMENTS_INDEX_PATH, + REPORT_INDEX_FORMAT, + REPORT_PAGE_FORMAT, + REPORTS_INDEX_PATH, + citedInHref, + momentViewPath, + reportAssetPath, + reportPagePath, + reportsIndexPath, + reportViewPath, +} from "./views"; + +// The shared reader (reader-server.ts) under a base of its own: it reads +// what compose would write under that base, and nothing under another. + +function publicDirWith(files: Record<string, unknown>): string { + const dir = fs.mkdtempSync(path.join(os.tmpdir(), "report-reader-")); + for (const [urlPath, value] of Object.entries(files)) { + const file = path.join(dir, ...urlPath.split("/").filter(Boolean)); + fs.mkdirSync(path.dirname(file), { recursive: true }); + fs.writeFileSync(file, typeof value === "string" ? value : JSON.stringify(value)); + } + return dir; +} + +const page = (id: string) => ({ format: REPORT_PAGE_FORMAT, id, kind: "sweep", title: `Title ${id}`, sections: [] }); + +test("the site's base is /reports/, and every path helper defaults to it", () => { + assert.equal(SITE_REPORTS_BASE, "/reports/"); + assert.equal(REPORTS_INDEX_PATH, "/reports/index.json"); + assert.equal(reportPagePath("a"), "/reports/a/"); + assert.equal(reportHistoryPagePath("a"), "/reports/a/history/"); +}); + +test("a base names every report path", () => { + assert.equal(reportsIndexPath("/articles/"), "/articles/index.json"); + assert.equal(reportPagePath("a", "/articles/"), "/articles/a/"); + assert.equal(reportViewPath("a", "/articles/"), "/articles/a/page.json"); + assert.equal(reportAssetPath("a", "./stills/x.png", "/articles/"), "/articles/a/stills/x.png"); + assert.equal(reportHistoryViewPath("a", "/articles/"), "/articles/a/history/history.json"); + assert.equal(citedInHref({ reportId: "a", sectionId: "s1", claimId: "k1" }, "/articles/"), "/articles/a/#k1"); +}); + +test("a base is lowercase segments with a slash on both ends", () => { + for (const ok of ["/reports/", "/pages/", "/a/b/"]) assert.ok(isReportBase(ok), ok); + for (const bad of ["reports/", "/reports", "/", "/Reports/", "//", "/../", 3]) assert.ok(!isReportBase(bad), String(bad)); + assert.equal(reportBaseDir("/reports/"), "reports"); + assert.equal(reportBaseDir("/a/b/"), "a/b"); +}); + +test("the reader reads its own base's views, in index order, and nothing under another base", () => { + const dir = publicDirWith({ + [reportsIndexPath("/articles/")]: { + format: REPORT_INDEX_FORMAT, + reports: [{ id: "two" }, { id: "Not An Id" }, { id: "one" }], + }, + [reportViewPath("one", "/articles/")]: page("one"), + [reportViewPath("two", "/articles/")]: page("two"), + [reportViewPath("one")]: page("one"), + [reportHistoryViewPath("one", "/articles/")]: { + format: REPORT_HISTORY_FORMAT, + reportId: "one", + revisions: [{ revision: 1 }], + }, + [MOMENTS_INDEX_PATH]: { format: MOMENT_INDEX_FORMAT, moments: ["ch/post1", "bad"] }, + [momentViewPath("ch/post1")]: { format: MOMENT_PAGE_FORMAT, key: "ch/post1" }, + }); + const articles = createReportReader({ publicDir: dir, base: "/articles/" }); + assert.equal(articles.base, "/articles/"); + assert.deepEqual(articles.reportIds(), ["two", "one"]); + assert.ok(articles.hasReports()); + assert.equal(articles.readReportView("one")?.title, "Title one"); + assert.equal(articles.readReportView("../one"), null); + assert.equal(articles.readReportHistory("one")?.reportId, "one"); + assert.equal(articles.readReportHistory("two"), null); + assert.equal(articles.onlyReportView(), null); + assert.deepEqual(articles.momentKeys(), ["ch/post1"]); + assert.equal(articles.readMomentView("ch/post1")?.key, "ch/post1"); + assert.equal(articles.readMomentView("bad"), null); + + // The site's base (the default) has no index here: no reports. + const site = createReportReader({ publicDir: () => dir }); + assert.equal(site.base, SITE_REPORTS_BASE); + assert.equal(site.readReportIndex(), null); + assert.deepEqual(site.reportIds(), []); + assert.ok(!site.hasReports()); +}); + +test("a missing, unreadable or foreign file reads as none", () => { + const dir = publicDirWith({ + [REPORTS_INDEX_PATH]: { format: "something-else", reports: [{ id: "a" }] }, + [reportViewPath("a")]: "{not json", + }); + const reader = createReportReader({ publicDir: dir }); + assert.equal(reader.readReportIndex(), null); + assert.equal(reader.readReportView("a"), null); + assert.equal(reader.readReportView("b"), null); + assert.deepEqual(reader.momentKeys(), []); +}); + +test("one report: onlyReportView is it", () => { + const dir = publicDirWith({ + [REPORTS_INDEX_PATH]: { format: REPORT_INDEX_FORMAT, reports: [{ id: "solo" }] }, + [reportViewPath("solo")]: page("solo"), + }); + assert.equal(createReportReader({ publicDir: dir }).onlyReportView()?.id, "solo"); +}); + +test("a report's metadata: its full title, its subtitle, its feeds", () => { + const md = reportMetadata({ + ...page("a"), + series: "Series", + subtitle: "Sub", + feeds: { rss: "https://x.example/reports/a/feed.xml", json: "https://x.example/reports/a/feed.json" }, + } as unknown as Parameters<typeof reportMetadata>[0]); + assert.equal(md.title, "Series: Title a"); + assert.equal(md.description, "Sub"); + assert.deepEqual(Object.keys(md.alternates?.types ?? {}), ["application/rss+xml", "application/feed+json"]); +}); diff --git a/common/lib/report/reader-server.ts b/common/lib/report/reader-server.ts @@ -0,0 +1,145 @@ +import fs from "node:fs"; +import path from "node:path"; +import { parseMomentKey } from "../citations/moments"; +import { isReportId } from "./schema"; +import { REPORT_HISTORY_FORMAT, reportHistoryViewPath, type ReportHistoryView } from "./revisions"; +import { SITE_REPORTS_BASE, type ReportBase } from "./routes"; +import { + MOMENT_INDEX_FORMAT, + MOMENT_PAGE_FORMAT, + MOMENTS_INDEX_PATH, + REPORT_INDEX_FORMAT, + REPORT_PAGE_FORMAT, + REPORT_FEED_MIME, + momentViewPath, + reportFullTitle, + reportsIndexPath, + reportViewPath, + type MomentIndexView, + type MomentPageView, + type ReportIndexView, + type ReportPageView, +} from "./views"; + +// THE REPORT READER — the report and moment views compose's reports stage +// writes into a build's public dir (./views.ts names every file), read at +// build time by the pages that render them (common/components/report/). One +// reader for every build that renders reports: a site reads its own under +// SITE_REPORTS_BASE, another build names its base (./routes.ts) and its +// public dir. +// +// Every read is tolerant: a file that is absent, unreadable or of another +// format reads as "none", so a build without reports builds exactly as before +// and one with none renders its empty state. Read synchronously — a static +// export, evaluated once per build. + +export type ReportReaderOptions = { + // The build's public dir, or a function returning it (read on every call, + // so a caller's lazily-resolved paths stay lazy). + publicDir: string | (() => string); + // Where this build serves its reports; a site's by default. + base?: ReportBase; +}; + +export type ReportReader = { + readonly base: ReportBase; + readReportIndex(): ReportIndexView | null; + // Whether the build has a report to link to. + hasReports(): boolean; + // The report ids to build pages for, in index order (only well-formed ids: + // each is a path segment). + reportIds(): string[]; + readReportView(reportId: string): ReportPageView | null; + // A report's revision history (`<base><id>/history/history.json`), or null + // when compose published none for it. + readReportHistory(reportId: string): ReportHistoryView | null; + // The build's one report, when it publishes exactly one. + onlyReportView(): ReportPageView | null; + // The moment keys to build pages for (only keys exactly as momentKey spells + // them: each segment is a path segment of a page written to disk). + momentKeys(): string[]; + readMomentView(key: string): MomentPageView | null; +}; + +export function createReportReader(opts: ReportReaderOptions): ReportReader { + const base = opts.base ?? SITE_REPORTS_BASE; + const publicDir = () => (typeof opts.publicDir === "function" ? opts.publicDir() : opts.publicDir); + + function readView<T extends { format: string }>(urlPath: string, format: T["format"]): T | null { + try { + const file = path.join(publicDir(), ...urlPath.split("/").filter(Boolean)); + const parsed = JSON.parse(fs.readFileSync(file, "utf8")) as T; + return parsed && parsed.format === format ? parsed : null; + } catch { + return null; + } + } + + const reader: ReportReader = { + base, + readReportIndex() { + const v = readView<ReportIndexView>(reportsIndexPath(base), REPORT_INDEX_FORMAT); + return v && Array.isArray(v.reports) ? v : null; + }, + hasReports() { + return (reader.readReportIndex()?.reports.length ?? 0) > 0; + }, + reportIds() { + return (reader.readReportIndex()?.reports ?? []).map((r) => r.id).filter(isReportId); + }, + readReportView(reportId) { + if (!isReportId(reportId)) return null; + const v = readView<ReportPageView>(reportViewPath(reportId, base), REPORT_PAGE_FORMAT); + return v && v.id === reportId && Array.isArray(v.sections) ? v : null; + }, + readReportHistory(reportId) { + if (!isReportId(reportId)) return null; + const v = readView<ReportHistoryView>(reportHistoryViewPath(reportId, base), REPORT_HISTORY_FORMAT); + return v && v.reportId === reportId && Array.isArray(v.revisions) && v.revisions.length > 0 ? v : null; + }, + onlyReportView() { + const ids = reader.reportIds(); + return ids.length === 1 ? reader.readReportView(ids[0]) : null; + }, + momentKeys() { + const v = readView<MomentIndexView>(MOMENTS_INDEX_PATH, MOMENT_INDEX_FORMAT); + return (Array.isArray(v?.moments) ? v.moments : []).filter((k) => parseMomentKey(k) !== null); + }, + readMomentView(key) { + if (!parseMomentKey(key)) return null; + const v = readView<MomentPageView>(momentViewPath(key), MOMENT_PAGE_FORMAT); + return v && v.key === key ? v : null; + }, + }; + return reader; +} + +// A report's page metadata: the title as one line names it (`<series>: +// <title>`, the layout's template adds the build's name), the subtitle as the +// description, and its timeline's feeds when it publishes them (a +// `<link rel="alternate">` each, by absolute URL: the layouts set no +// metadataBase). Shaped as Next's `Metadata` without importing it (its types +// would bring Next's globals into every package that imports common/lib). +export type ReportPageMetadata = { + title: string; + description?: string; + alternates?: { types: Record<string, { url: string; title: string }[]> }; +}; + +export function reportMetadata(view: ReportPageView): ReportPageMetadata { + const title = reportFullTitle(view); + return { + title, + ...(view.subtitle ? { description: view.subtitle } : {}), + ...(view.feeds + ? { + alternates: { + types: { + [REPORT_FEED_MIME.rss]: [{ url: view.feeds.rss, title }], + [REPORT_FEED_MIME.json]: [{ url: view.feeds.json, title }], + }, + }, + } + : {}), + }; +} diff --git a/common/lib/report/revisions.ts b/common/lib/report/revisions.ts @@ -9,9 +9,10 @@ // (`claimChanges`), both computed at compose into `history.json` // (ReportHistoryView), so the page only renders. // -// Pure, no imports but types: the export site's pages can use it. +// Pure, no imports but types and ./routes: the export site's pages can use it. import type { Claim, Report, ReportEntry } from "./schema"; +import { SITE_REPORTS_BASE, type ReportBase } from "./routes"; export const REPORT_HISTORY_FORMAT = "archilyzer-report-history"; export const REPORT_HISTORY_VERSION = 1; @@ -21,17 +22,17 @@ export const REPORT_HISTORY_BRANCH = "main"; // ─── Where it is published (site-root paths) ─── -export function reportHistoryPagePath(reportId: string): string { - return `/reports/${reportId}/history/`; +export function reportHistoryPagePath(reportId: string, base: ReportBase = SITE_REPORTS_BASE): string { + return `${base}${reportId}/history/`; } -export function reportHistoryViewPath(reportId: string): string { - return `/reports/${reportId}/history/history.json`; +export function reportHistoryViewPath(reportId: string, base: ReportBase = SITE_REPORTS_BASE): string { + return `${base}${reportId}/history/history.json`; } // The dumb-HTTP clone of the report's history: `git clone <site>/reports/<id>/history/repo`. -export function reportHistoryRepoPath(reportId: string): string { - return `/reports/${reportId}/history/repo`; +export function reportHistoryRepoPath(reportId: string, base: ReportBase = SITE_REPORTS_BASE): string { + return `${base}${reportId}/history/repo`; } // What a published clone holds, by path relative to it (publish/reportHistory.ts diff --git a/common/lib/report/routes.ts b/common/lib/report/routes.ts @@ -0,0 +1,32 @@ +// WHERE A BUILD SERVES ITS REPORTS — the base path every report path hangs off. +// +// One renderer (common/components/report/, read through ./reader-server.ts) +// serves a report under whichever base its build gives it: a site serves its +// own under SITE_REPORTS_BASE, and the homepage's articles will be served under +// their own base (plans/reports-on-homepage.md). Every path helper in ./views.ts +// and ./revisions.ts takes the base as its last argument and defaults to the +// site's, so a caller that names none is a site's. +// +// Moments (`/m/<key>/`) and evidence clips (`/media/clips/…`) are not under a +// base: one build serves one set of them, whichever reports cite them. +// +// Pure, no imports: the export site's pages and the browser can use it. + +// A base is a site-root path with a leading and a trailing slash: `/reports/`. +export type ReportBase = `/${string}/`; + +// A site's reports. +export const SITE_REPORTS_BASE: ReportBase = "/reports/"; + +const BASE_RE = /^\/(?:[a-z0-9][a-z0-9-]*\/)+$/; + +// Whether `v` is a usable base: lowercase path segments, slashes on both ends. +export function isReportBase(v: unknown): v is ReportBase { + return typeof v === "string" && BASE_RE.test(v); +} + +// The base's top directory under a public dir or an out dir, `reports` for +// `/reports/`. +export function reportBaseDir(base: ReportBase): string { + return base.split("/").filter(Boolean).join("/"); +} diff --git a/common/lib/report/views.ts b/common/lib/report/views.ts @@ -60,6 +60,7 @@ import type { ReportHistoryRef } from "./revisions"; import { effectiveUpdated, entriesNewestFirst } from "./entries"; import type { Claim, Report, ReportKind, ReportSlidesSpec, SlideSpec } from "./schema"; import { reportCitationNumbers } from "./uses"; +import { SITE_REPORTS_BASE, type ReportBase } from "./routes"; import { resolveVerdicts, VERDICTS, type Verdict, type VerdictStyle } from "./verdicts"; export const REPORT_VIEWS_VERSION = 1; @@ -70,8 +71,15 @@ export const MOMENT_INDEX_FORMAT = "archilyzer-moment-index"; export const MOMENT_PAGE_FORMAT = "archilyzer-moment-page"; // ─── Where each view lives (site-root URL paths; a file under the public dir) ─── +// +// Every report path takes the base its build serves reports under (./routes.ts) +// and defaults to a site's. + +export function reportsIndexPath(base: ReportBase = SITE_REPORTS_BASE): string { + return `${base}index.json`; +} -export const REPORTS_INDEX_PATH = "/reports/index.json"; +export const REPORTS_INDEX_PATH = reportsIndexPath(); export const MOMENTS_INDEX_PATH = "/m/index.json"; // THE PLACEHOLDER PARAM. A static export refuses a dynamic route whose @@ -82,16 +90,20 @@ export const MOMENTS_INDEX_PATH = "/m/index.json"; export const REPORT_PLACEHOLDER_ID = "_none"; export const MOMENT_PLACEHOLDER_KEY = "_none"; -export function reportPagePath(reportId: string): string { - return `/reports/${reportId}/`; +export function reportPagePath(reportId: string, base: ReportBase = SITE_REPORTS_BASE): string { + return `${base}${reportId}/`; } -export function reportViewPath(reportId: string): string { - return `/reports/${reportId}/page.json`; +export function reportViewPath(reportId: string, base: ReportBase = SITE_REPORTS_BASE): string { + return `${base}${reportId}/page.json`; } -export function reportCitationsDownloadPath(reportId: string, format: "json" | "csv"): string { - return `/reports/${reportId}/citations.${format}`; +export function reportCitationsDownloadPath( + reportId: string, + format: "json" | "csv", + base: ReportBase = SITE_REPORTS_BASE, +): string { + return `${base}${reportId}/citations.${format}`; } // A report's exports (publish/reportExports.ts): the whole report as files a @@ -110,8 +122,12 @@ export const REPORT_EXPORT_FILENAMES: Readonly<Record<ReportExportFormat, string zip: "evidence-pack.zip", }; -export function reportExportDownloadPath(reportId: string, format: ReportExportFormat): string { - return `/reports/${reportId}/${REPORT_EXPORT_FILENAMES[format]}`; +export function reportExportDownloadPath( + reportId: string, + format: ReportExportFormat, + base: ReportBase = SITE_REPORTS_BASE, +): string { + return `${base}${reportId}/${REPORT_EXPORT_FILENAMES[format]}`; } // A report's feeds of its timeline (./feeds.ts): RSS 2.0 and JSON Feed 1.1, @@ -128,15 +144,15 @@ export const REPORT_FEED_MIME: Readonly<Record<ReportFeedFormat, string>> = { json: "application/feed+json", }; -export function reportFeedPath(reportId: string, format: ReportFeedFormat): string { - return `/reports/${reportId}/${REPORT_FEED_FILENAMES[format]}`; +export function reportFeedPath(reportId: string, format: ReportFeedFormat, base: ReportBase = SITE_REPORTS_BASE): string { + return `${base}${reportId}/${REPORT_FEED_FILENAMES[format]}`; } // A file the report names relative to its own directory (a still, // `stills/a01.png` — validated by lib/report/validate.ts never to leave it), // as published. -export function reportAssetPath(reportId: string, relPath: string): string { - return `/reports/${reportId}/${relPath.replace(/^\.\//, "")}`; +export function reportAssetPath(reportId: string, relPath: string, base: ReportBase = SITE_REPORTS_BASE): string { + return `${base}${reportId}/${relPath.replace(/^\.\//, "")}`; } export function momentViewPath(key: string): string { @@ -792,15 +808,22 @@ export function reportIndexEntry(view: ReportPageView): ReportIndexEntry { // The anchor of a place in a report: the claim, else the section, else the // timeline entry, else none (the summary — the page's top). -export function citedInHref(entry: Pick<CitedIn, "reportId" | "sectionId" | "claimId" | "entryId">): string { +export function citedInHref( + entry: Pick<CitedIn, "reportId" | "sectionId" | "claimId" | "entryId">, + base: ReportBase = SITE_REPORTS_BASE, +): string { const anchor = entry.claimId ?? entry.sectionId ?? entry.entryId; - return `${reportPagePath(entry.reportId)}${anchor ? `#${anchor}` : ""}`; + return `${reportPagePath(entry.reportId, base)}${anchor ? `#${anchor}` : ""}`; } // A moment's "cited in" entries (lib/report/citedIn.ts buildCitedIn), resolved // against the reports' views for their titles; an entry whose report has no // view is dropped. -export function citedInViews(entries: readonly CitedIn[], reports: readonly ReportPageView[]): CitedInView[] { +export function citedInViews( + entries: readonly CitedIn[], + reports: readonly ReportPageView[], + base: ReportBase = SITE_REPORTS_BASE, +): CitedInView[] { const byId = new Map(reports.map((r) => [r.id, r])); const out: CitedInView[] = []; for (const e of entries) { @@ -812,7 +835,7 @@ export function citedInViews(entries: readonly CitedIn[], reports: readonly Repo out.push( defined({ ...e, - href: citedInHref(e), + href: citedInHref(e, base), reportTitle: reportFullTitle(report), sectionTitle: section?.title, entryTitle: entry?.title, diff --git a/export/app/(workspace)/ask/page.tsx b/export/app/(workspace)/ask/page.tsx @@ -4,7 +4,7 @@ import { currentSite } from "../../lib/site"; import { instanceMode } from "../../lib/mode"; import AskHub from "../../ask/AskHub"; import { isCitedSite } from "yt-dlp-transcript-common/lib/siteSchema"; -import { NotOnCitedSite } from "../../components/reports/parts"; +import { NotOnCitedSite } from "../../components/NotOnCitedSite"; export const metadata: Metadata = { title: "Ask AI" }; diff --git a/export/app/(workspace)/page.tsx b/export/app/(workspace)/page.tsx @@ -2,11 +2,11 @@ import type { Metadata } from "next"; import { isCitedSite } from "yt-dlp-transcript-common/lib/siteSchema"; import { currentSite } from "../lib/site"; import { instanceMode } from "../lib/mode"; -import { onlyReportView, readReportIndex, reportMetadata } from "../lib/reports"; +import { REPORTS_BASE, onlyReportView, readReportIndex, reportMetadata } from "../lib/reports"; import NewSinceLastVisit from "../components/NewSinceLastVisit"; import HubHome from "../components/hub/HubHome"; -import ReportIndex from "../components/reports/ReportIndex"; -import ReportArticle from "../components/reports/ReportArticle"; +import ReportIndex from "yt-dlp-transcript-common/components/report/ReportIndex"; +import ReportArticle from "yt-dlp-transcript-common/components/report/ReportArticle"; // A cited site with one report: the home page IS the report, so its tab names // the report as the report's own page does. Every other home keeps the @@ -37,7 +37,7 @@ export default async function Home() { // heading of its own: the header already names the site. if (isCitedSite(settings)) { const only = onlyReportView(); - if (only) return <ReportArticle view={only} />; + if (only) return <ReportArticle view={only} base={REPORTS_BASE} />; return <ReportIndex index={readReportIndex()} heading={null} tagline={settings.homeTagline} />; } const { countTranscripts } = await import("yt-dlp-transcript-common/lib/transcripts"); diff --git a/export/app/components/NotOnCitedSite.tsx b/export/app/components/NotOnCitedSite.tsx @@ -0,0 +1,21 @@ +import Link from "next/link"; +import { EmptyState, textLink } from "yt-dlp-transcript-common/components/report/parts"; +import { reportIds } from "../lib/reports"; + +// What a corpus-shaped route (search's chat, downloads, duplicates, offline) +// renders on a CITED site, which publishes only its reports and their moments. +// The route still exists in the static build (every route does); it shows +// nothing of the corpus and points at the home page -- the index, or the one +// report. +export function NotOnCitedSite({ title }: { title: string }) { + const one = reportIds().length === 1; + return ( + <EmptyState title={title}> + This site publishes its reports only.{" "} + <Link href="/" className={textLink}> + {one ? "Read the report" : "Read the reports"} + </Link> + . + </EmptyState> + ); +} diff --git a/export/app/components/reports/MomentArticle.tsx b/export/app/components/reports/MomentArticle.tsx @@ -1,180 +0,0 @@ -import { VerificationBadge } from "yt-dlp-transcript-common/components/citations/VerificationBadge"; -import { VerdictChip } from "yt-dlp-transcript-common/components/report/VerdictChip"; -import { formatTimestamp } from "yt-dlp-transcript-common/lib/vtt"; -import { CITATION_KIND_LABELS, spanLabel, type MomentPageView } from "yt-dlp-transcript-common/lib/report/views"; -import { ExternalLinkText, Eyebrow, dateLabel, textLink } from "./parts"; - -// ONE CITED MOMENT, from its view (common/lib/report/views.ts): a span's -// self-hosted evidence clip (video, or audio with its poster) or a post's -// captured shot and text; the quote and what checking it found; the transcript -// lines around the span; the record's metadata and a link to the original at -// its time (and into the corpus on a full site); and every place on the site -// that cites it. - -export default function MomentArticle({ view }: { view: MomentPageView }) { - const r = view.record; - const isSpan = view.kind === "video" || view.kind === "audio"; - const span = isSpan && view.start !== undefined && view.end !== undefined ? spanLabel(view.start, view.end) : null; - const meta = [r.channelTitle ?? r.channel, dateLabel(view.date ?? r.date), span].filter(Boolean).join(" · "); - const title = r.title ?? (view.kind === "post" ? (view.post?.author ?? r.channelTitle ?? r.channel) : `${r.channel}/${r.id}`); - const clip = view.clip; - const padded = - clip && view.start !== undefined && view.end !== undefined && (clip.start < view.start || clip.end > view.end); - - return ( - <article data-moment={view.key} data-moment-kind={view.kind} className="mx-auto flex w-full max-w-3xl flex-col gap-6"> - <header className="flex flex-col gap-2"> - <Eyebrow>Cited {CITATION_KIND_LABELS[view.kind].toLowerCase()}</Eyebrow> - <h1 className="font-display text-2xl font-semibold leading-tight tracking-tight text-foreground sm:text-3xl"> - {title} - </h1> - {meta && <p className="font-mono text-xs text-muted-foreground">{meta}</p>} - </header> - - {clip && view.kind === "video" && ( - <video - data-evidence-clip="" - controls - playsInline - preload="metadata" - poster={clip.poster} - src={clip.src} - className="aspect-video w-full rounded-lg border border-border bg-black" - /> - )} - {clip && view.kind === "audio" && ( - <div className="flex flex-col gap-3"> - {clip.poster && ( - // eslint-disable-next-line @next/next/no-img-element -- a published file of unknown size; the export serves images unoptimized - <img src={clip.poster} alt="" className="aspect-video w-full rounded-lg border border-border object-cover" /> - )} - <audio data-evidence-clip="" controls preload="metadata" src={clip.src} className="w-full" /> - </div> - )} - {clip && padded && ( - <p className="-mt-3 text-xs text-muted-foreground"> - The clip runs {spanLabel(clip.start, clip.end)}, a little either side of the cited {span} for context. - </p> - )} - {view.post?.shot && ( - // eslint-disable-next-line @next/next/no-img-element -- a published file of unknown size; the export serves images unoptimized - <img - src={view.post.shot} - alt={`Screenshot of the post${view.post.author ? ` by ${view.post.author}` : ""}`} - className="w-full max-w-xl rounded-lg border border-border" - /> - )} - - <div className="flex flex-col gap-2"> - <blockquote className="border-l-4 border-brand pl-4 text-lg leading-relaxed text-foreground"> - {view.speaker && <span className="font-medium text-muted-foreground">{view.speaker}: </span>} - <q className="italic">{view.quote}</q> - </blockquote> - <VerificationBadge verification={view.verification} /> - </div> - - {view.post && view.post.text.trim() !== view.quote.trim() && ( - <div className="flex flex-col gap-1"> - <p className="font-mono text-[10px] uppercase tracking-[0.16em] text-muted-foreground">The post</p> - <p className="whitespace-pre-line text-sm leading-relaxed text-foreground">{view.post.text}</p> - </div> - )} - {view.post?.media && view.post.media.length > 0 && ( - <ul className="flex flex-col gap-3"> - {view.post.media.map((m) => - m.kind === "image" ? ( - <li key={m.src}> - {/* eslint-disable-next-line @next/next/no-img-element -- a published file of unknown size; the export serves images unoptimized */} - <img src={m.src} alt="" className="max-w-full rounded-md border border-border" /> - </li> - ) : ( - <li key={m.src}> - <video src={m.src} controls playsInline preload="metadata" className="w-full rounded-md border border-border" /> - </li> - ), - )} - </ul> - )} - - {view.cues && view.cues.length > 0 && ( - <section aria-labelledby="cues-heading" className="flex flex-col gap-2"> - <h2 id="cues-heading" className="font-mono text-[10px] uppercase tracking-[0.16em] text-muted-foreground"> - Transcript - </h2> - <ol data-cue-lines="" className="flex flex-col rounded-lg border border-border bg-card text-sm"> - {view.cues.map((c, i) => ( - <li - key={`${c.start}-${i}`} - data-in-span={c.inSpan ? "" : undefined} - className={ - c.inSpan - ? "flex gap-3 bg-brand-soft px-3 py-1.5 text-foreground" - : "flex gap-3 px-3 py-1.5 text-muted-foreground" - } - > - <span className="w-14 shrink-0 font-mono text-xs leading-6 tabular-nums">{formatTimestamp(c.start)}</span> - <span className="leading-6">{c.text}</span> - </li> - ))} - </ol> - </section> - )} - - {(r.originalUrl || r.corpusUrl) && ( - <p className="flex flex-wrap gap-x-4 gap-y-1 text-sm"> - {r.originalUrl && ( - <ExternalLinkText href={r.originalUrl}> - {isSpan && view.start !== undefined - ? `${r.originalLabel ?? "Original"} at ${formatTimestamp(view.start)}` - : "Original post"} - </ExternalLinkText> - )} - {r.downloads?.map((d) => ( - <ExternalLinkText key={d.url} href={d.url}> - {d.label} - </ExternalLinkText> - ))} - {r.corpusUrl && ( - <a href={r.corpusUrl} className={textLink}> - Open in the archive - </a> - )} - </p> - )} - - {view.citedIn.length > 0 && ( - <section aria-labelledby="cited-in-heading" className="flex flex-col gap-2 border-t border-border pt-5"> - <h2 id="cited-in-heading" className="font-display text-xl font-semibold text-foreground"> - Cited in - </h2> - <ul data-cited-in="" className="flex flex-col gap-2"> - {view.citedIn.map((e) => ( - <li - key={`${e.reportId}/${e.sectionId}/${e.claimId}/${e.entryId ?? ""}/${e.citationId}`} - className="flex flex-col gap-1 rounded-lg border border-border bg-card p-3 text-sm" - > - <a href={e.href} className={`font-medium ${textLink}`}> - {e.reportTitle} - </a> - <div className="flex flex-wrap items-center gap-2 text-muted-foreground"> - {e.verdict && e.verdictStyle && <VerdictChip verdict={e.verdict} style={e.verdictStyle} />} - {e.sectionTitle ? ( - <span>{e.sectionTitle}</span> - ) : e.entryId ? ( - <span>Timeline{e.entryTitle ? ` — ${e.entryTitle}` : ""}</span> - ) : ( - !e.sectionId && <span>Summary</span> - )} - {(e.claimTitle ?? e.claimText) && ( - <span className="text-foreground">— {e.claimTitle ?? e.claimText}</span> - )} - {e.number !== undefined && <span className="font-mono text-xs">[{e.number}]</span>} - </div> - </li> - ))} - </ul> - </section> - )} - </article> - ); -} diff --git a/export/app/components/reports/ReportArticle.tsx b/export/app/components/reports/ReportArticle.tsx @@ -1,538 +0,0 @@ -import { ArrowDownToLine, Rss } from "lucide-react"; -import { AddedMark, CitationCard } from "yt-dlp-transcript-common/components/citations/CitationCard"; -import { CitationsProvider } from "yt-dlp-transcript-common/components/citations/CitationsContext"; -import { CitedMarkdown } from "yt-dlp-transcript-common/components/citations/CitedMarkdown"; -import { ReferenceList } from "yt-dlp-transcript-common/components/citations/ReferenceList"; -import { VerdictChip, VerdictTally } from "yt-dlp-transcript-common/components/report/VerdictChip"; -import { ReportReader } from "yt-dlp-transcript-common/components/report/slides/ReportReader"; -import { REPORT_PAGE_ANCHOR_IDS } from "yt-dlp-transcript-common/lib/report/slideRules"; -import { hasSlides } from "yt-dlp-transcript-common/lib/report/slides"; -import type { SourceArchive } from "yt-dlp-transcript-common/lib/citations/schema"; -import { - entryDateLabel, - foundGroups, - orderedCitations, - reportDateParts, - reportRevisionLabel, - reportViewPath, - sourceAnchor, - verdictTally, - type CitationView, - type ClaimView, - type EntryView, - type ReportPageView, - type SourceCitationView, -} from "yt-dlp-transcript-common/lib/report/views"; -import { ArchiveList, ReportName, SourceBlock, SubjectCard, textLink } from "./parts"; - -// ONE REPORT, from its view (common/lib/report/views.ts): the header (its -// series and its title, or the title alone; one line of dates and the -// revision, linked to its history; the document under review as a card on its -// colour's rail, with its archive links; the subtitle), the three tiers each -// opened by a depth marker — the quick take (a fact-check's tally, the -// summary), the timeline when the report keeps one (dated entries, newest -// first, each its own anchor), what the check found, and every claim with its evidence: each -// claim its verdict and flag, the document's own sentence (its still), the -// findings with their inline citations, and the evidence cards (what the -// report added first, marked; what the document gave itself folded away -// last) — then the numbered reference list the inline markers jump to, and -// the downloads: the report as files (HTML, PDF, Markdown, the evidence pack) -// and its citations as data. -// -// A report with a timeline on a site with a public URL publishes feeds of it -// (common/lib/report/feeds.ts): the header links them ("Subscribe"), and the -// page's metadata names them (lib/reports.ts reportMetadata). -// -// ONE ARTICLE, THREE SHAPES (release 22): the view switch (Article | Slides | -// Overview — common/components/report/slides/ReportReader) follows the -// header and sticks under the site's header while the article scrolls, so a -// switch keeps the place the reader is at; every anchor in the article lands -// below the two bars (`scroll-mt-32`: the site header's 57 px and the -// switch's 54). Every place a slide stands for has its id here: the header, the quick -// take, what the check found, each section and claim, and the end matter -// (lib/report/slideRules.ts REPORT_PAGE_ANCHOR_IDS). The article itself stays -// this static page; the other views are built in the browser from page.json. - -const proseClass = "text-[0.95rem] leading-relaxed text-foreground"; - -const DOWNLOADS: readonly (readonly [keyof NonNullable<ReportPageView["downloads"]>, string])[] = [ - ["html", "HTML"], - ["pdf", "PDF"], - ["md", "Markdown"], - ["slides", "Slides"], - ["slides-pdf", "Slides PDF"], - ["zip", "Evidence pack"], - ["json", "Citations JSON"], - ["csv", "CSV"], -]; - -// A claim's sentence in a quoted document: its still (or its words), on a rail -// in the document's colour (its `accent`, else the border colour) — the same -// colour as the document's box, so the sentences and the box read as one -// source. A sentence of the document under review needs no link to it: the -// rail says whose it is. Another document's sentence links to its box. -function SourceSentence({ - c, - archives, - isSubject, -}: { - c: SourceCitationView; - archives: readonly SourceArchive[] | undefined; - isSubject: boolean; -}) { - const hasArchives = !!archives && archives.length > 0; - return ( - <figure - data-source-sentence={c.id} - className={`flex flex-col gap-1.5 border-l-4 pl-3${c.sourceAccent ? "" : " border-border"}`} - style={c.sourceAccent ? { borderLeftColor: c.sourceAccent } : undefined} - > - {c.image ? ( - // eslint-disable-next-line @next/next/no-img-element -- a published file of unknown size; the export serves images unoptimized - <img - src={c.image} - alt={c.quote} - loading="lazy" - className="w-full max-w-xl rounded-md border border-border bg-white object-contain object-left-top" - /> - ) : ( - <blockquote className="italic text-muted-foreground"> - <q>{c.quote}</q> - </blockquote> - )} - {(!isSubject || hasArchives) && ( - <figcaption className="flex flex-col gap-1 text-xs text-muted-foreground"> - {!isSubject && ( - <a href={`#${sourceAnchor(c.sourceId)}`} className={textLink}> - from {c.sourceTitle} - </a> - )} - {/* Only the document's archive links that sit in this sentence; the - full list is with the document, once. */} - {hasArchives && <ArchiveList archives={archives} />} - </figcaption> - )} - </figure> - ); -} - -// A claim's flag: a quiet pill in the accent, behind the project's mark (the -// mark added evidence wears: the two read as the report's own marks). -function FlagPill({ flag, className }: { flag: string; className?: string }) { - return ( - <span - data-claim-flag="" - className={`inline-flex shrink-0 items-center gap-1.5 rounded-full border border-brand/40 bg-brand-soft px-2.5 py-0.5 text-xs font-medium text-brand${className ? ` ${className}` : ""}`} - > - <AddedMark className="size-3" /> - {flag} - </span> - ); -} - -// Where a tier of the page begins: a hairline with, at its left, how deep it -// goes (one, two or three dots filled in the accent). Decoration only: the -// tier's own label or heading names it. -function TierMarker({ depth }: { depth: 1 | 2 | 3 }) { - return ( - <div data-tier-marker={depth} aria-hidden="true" className="flex items-center gap-2.5"> - <span className="flex items-center gap-1"> - {[1, 2, 3].map((i) => ( - <span - key={i} - data-depth-dot={i <= depth ? "filled" : "empty"} - className={ - i <= depth - ? "size-1.5 rounded-full bg-brand" - : "size-1.5 rounded-full border border-muted-foreground/60" - } - /> - ))} - </span> - <span className="h-px flex-1 bg-border" /> - </div> - ); -} - -// A timeline entry: its date first and largest (what a timeline is read by), -// linking to its own anchor, then its title and its body. A dot on the -// timeline's rail marks it. -function Entry({ entry }: { entry: EntryView }) { - return ( - <li id={entry.id} data-entry={entry.id} className="relative flex scroll-mt-20 flex-col gap-1.5"> - <span - aria-hidden="true" - className="absolute top-[0.45rem] -left-[calc(1rem+4.5px)] size-2 rounded-full bg-brand ring-4 ring-background sm:-left-[calc(1.25rem+4.5px)]" - /> - <p className="flex flex-wrap items-baseline gap-x-2 font-mono text-sm"> - <a href={`#${entry.id}`} data-entry-date="" className="font-semibold text-brand hover:underline"> - <time dateTime={entry.date}>{entryDateLabel(entry.date)}</time> - </a> - {entry.updated && ( - <span className="text-xs text-muted-foreground"> - updated <time dateTime={entry.updated}>{entryDateLabel(entry.updated)}</time> - </span> - )} - </p> - <h3 className="font-display text-lg font-semibold leading-snug text-foreground">{entry.title}</h3> - <CitedMarkdown className={proseClass}> - {entry.body} - </CitedMarkdown> - </li> - ); -} - -// A claim: its verdict, flag and title; the document's own sentence (its -// still, else its verbatim words) when the claim cites one, else the claim as -// the report states it, plain; the findings; the evidence. -function Claim({ - claim, - view, - subjectNoun, -}: { - claim: ClaimView; - view: ReportPageView; - // What the document under review is called: "article" or "source". - subjectNoun: string; -}) { - const cited = claim.sourceQuote ? view.citations[claim.sourceQuote] : undefined; - const sentence = cited?.kind === "source" ? cited : undefined; - const evidence = claim.citations - .filter((id) => id !== claim.sourceQuote) - .map((id) => view.citations[id]) - .filter((c): c is CitationView => !!c); - // What the report adds comes first, marked; then evidence of unknown origin; - // what the document under review gave itself is folded away at the end. - const added = evidence.filter((c) => c.origin === "added"); - const unknown = evidence.filter((c) => c.origin === undefined); - const given = evidence.filter((c) => c.origin === "subject"); - const shown = [...added, ...unknown]; - const addedLabel = `Not in the ${subjectNoun}`; - return ( - <article - id={claim.id} - data-claim={claim.id} - className="flex scroll-mt-20 flex-col gap-3 rounded-lg border border-border bg-surface p-4 sm:p-5" - > - <div className="flex flex-wrap items-start gap-x-3 gap-y-2"> - {claim.verdict && <VerdictChip verdict={claim.verdict} style={view.verdicts[claim.verdict]} className="mt-0.5" />} - {claim.flag && <FlagPill flag={claim.flag} className="mt-0.5" />} - <h3 className="min-w-0 flex-1 basis-60 font-display text-lg font-semibold leading-snug text-foreground"> - <a href={`#${claim.id}`} className="hover:text-brand transition-colors"> - {claim.title ?? claim.text} - </a> - </h3> - </div> - {sentence ? ( - <SourceSentence c={sentence} archives={claim.archives} isSubject={sentence.sourceId === view.subject} /> - ) : ( - claim.title && ( - <p data-claim-text="" className="text-sm text-muted-foreground"> - {claim.text} - </p> - ) - )} - {claim.findings && ( - <CitedMarkdown className={proseClass}> - {claim.findings} - </CitedMarkdown> - )} - {evidence.length > 0 && ( - <div className="flex flex-col gap-2"> - <p className="font-mono text-[10px] uppercase tracking-[0.16em] text-muted-foreground">Evidence</p> - {shown.length > 0 && ( - <div className="grid gap-3 sm:grid-cols-2"> - {shown.map((c) => ( - <CitationCard key={c.id} citation={c} addedLabel={addedLabel} /> - ))} - </div> - )} - {given.length > 0 && ( - <details data-subject-evidence="" className="group"> - <summary className="cursor-pointer select-none font-mono text-xs text-muted-foreground hover:text-foreground"> - {`In the ${subjectNoun} (${given.length})`} - </summary> - <div className="mt-2 grid gap-3 sm:grid-cols-2"> - {given.map((c) => ( - <CitationCard key={c.id} citation={c} addedLabel={addedLabel} /> - ))} - </div> - </details> - )} - </div> - )} - </article> - ); -} - -export default function ReportArticle({ view }: { view: ReportPageView }) { - const isFactcheck = view.kind === "factcheck"; - const tally = isFactcheck ? verdictTally(view) : []; - const references = orderedCitations(view); - const subject = view.subject ? view.sources[view.subject] : undefined; - const subjectNoun = subject?.kind === "article" ? "article" : "source"; - const dates = reportDateParts(view); - const claimCount = view.sections.reduce((n, s) => n + s.claims.length, 0); - // The report as files (its exports), then its citations as data: only what - // compose published. - const downloads = DOWNLOADS.flatMap(([key, label]) => { - const href = view.downloads?.[key]; - return href ? [[key, label, href] as const] : []; - }); - const groups = isFactcheck ? foundGroups(view) : []; - const slides = hasSlides(view); - const jumps = [ - ...(groups.length > 0 ? [{ href: "#found", label: "What the check found" }] : []), - { href: "#claims", label: "Every claim" }, - ...(downloads.length > 0 ? [{ href: "#downloads", label: "Downloads" }] : []), - ]; - // Documents quoted that are not the subject, each shown once before the - // references. - const otherSources = Object.values(view.sources).filter((s) => s.id !== view.subject); - - return ( - // One citation map for every inline marker on the page (CitationsContext): - // serialized once, not once per marker. - <CitationsProvider citations={view.citations}> - <article - data-report={view.id} - className={`mx-auto flex w-full max-w-3xl flex-col gap-8${slides ? " [&_[id]]:scroll-mt-32" : ""}`} - > - {/* The report's name (its series on one line, its title on the next; - without a series, the title alone), one line of dates and the - revision, the document under review, the subtitle. */} - <header id={REPORT_PAGE_ANCHOR_IDS.head} className="flex scroll-mt-20 flex-col gap-3"> - <h1 className="font-display text-3xl font-semibold leading-tight tracking-tight text-foreground [overflow-wrap:anywhere] sm:text-4xl"> - <ReportName series={view.series} title={view.title} /> - </h1> - {(dates.length > 0 || view.history) && ( - <p data-report-dates="" className="font-mono text-xs text-muted-foreground"> - {dates.join(" · ")} - {view.history && ( - <> - {dates.length > 0 ? " · " : null} - <a href={view.history.href} data-report-revision={view.history.revision} - className="underline decoration-muted-foreground/40 underline-offset-2 hover:text-foreground hover:decoration-foreground" - > - {reportRevisionLabel(view.history.revision, view.history.current)} - </a> - </> - )} - </p> - )} - {view.feeds && ( - <p data-report-feeds="" className="flex items-center gap-1.5 font-mono text-xs text-muted-foreground"> - <Rss className="size-3.5" aria-hidden /> - Subscribe: - <a href={view.feeds.rss} type="application/rss+xml" data-feed="rss" className={textLink}> - RSS - </a> - <span aria-hidden="true">·</span> - <a href={view.feeds.json} type="application/feed+json" data-feed="json" className={textLink}> - JSON - </a> - </p> - )} - {subject && <SubjectCard source={subject} />} - {view.subtitle && <p className="text-lg text-muted-foreground">{view.subtitle}</p>} - </header> - - {/* The view switch: sticky just under the site's header (Header.tsx, - `sticky top-0`, 56 px and its border), within the article's box. */} - {slides && ( - <div data-report-views="" className="sticky top-14 z-10 flex items-center bg-background/80 py-2 backdrop-blur-md"> - <ReportReader pagePath={reportViewPath(view.id)} title={view.title} series={view.series} /> - </div> - )} - - {/* The report as a video, when it has one. */} - {view.video && ( - <figure data-report-video="" className="flex flex-col gap-2"> - <video - controls - playsInline - preload="metadata" - poster={view.video.poster} - src={view.video.src} - className="aspect-video w-full rounded-lg border border-border bg-black" - /> - {view.video.caption && ( - <figcaption className="text-sm text-muted-foreground">{view.video.caption}</figcaption> - )} - </figure> - )} - - {/* The quick take: the tally and the summary, then where to go next. */} - <section - id={REPORT_PAGE_ANCHOR_IDS.summary} - data-report-tier="1" - aria-label="In brief" - className="flex scroll-mt-20 flex-col gap-4" - > - <TierMarker depth={1} /> - {tally.length > 0 && ( - <div className="flex flex-col gap-2"> - <p className="font-mono text-[10px] uppercase tracking-[0.16em] text-muted-foreground"> - {claimCount} claim{claimCount === 1 ? "" : "s"} checked - </p> - <VerdictTally tally={tally} styles={view.verdicts} /> - </div> - )} - {view.summary && ( - <CitedMarkdown className={proseClass}> - {view.summary} - </CitedMarkdown> - )} - <p data-report-jumps="" className="flex flex-wrap gap-x-2 gap-y-1 text-sm"> - {jumps.map((j, i) => ( - <span key={j.href} className="whitespace-nowrap"> - {i > 0 && <span aria-hidden="true" className="mr-2 text-muted-foreground">·</span>} - <a href={j.href} className={textLink}> - {j.label} - </a> - </span> - ))} - </p> - </section> - - {/* The timeline: dated entries, newest first, on a rail. */} - {view.entries && view.entries.length > 0 && ( - <section data-report-timeline="" aria-labelledby="timeline-heading" className="flex flex-col gap-4"> - <h2 id="timeline-heading" className="font-display text-2xl font-semibold tracking-tight text-foreground"> - Timeline - </h2> - <ol className="ml-1 flex flex-col gap-7 border-l border-border pl-4 sm:pl-5"> - {view.entries.map((e) => ( - <Entry key={e.id} entry={e} /> - ))} - </ol> - </section> - )} - - {/* What the check found: every ruled claim by verdict, one line each. */} - {groups.length > 0 && ( - <section id="found" data-report-tier="2" aria-labelledby="found-heading" className="flex scroll-mt-20 flex-col gap-4"> - <TierMarker depth={2} /> - <h2 id="found-heading" className="font-display text-2xl font-semibold tracking-tight text-foreground"> - What the check found - </h2> - {groups.map((g) => ( - <div key={g.verdict} data-found-group={g.verdict} className="flex flex-col gap-2"> - <h3> - <VerdictChip verdict={g.verdict} style={view.verdicts[g.verdict]} count={g.claims.length} /> - </h3> - <ul className="flex flex-col gap-1.5 pl-1 text-sm"> - {g.claims.map((c) => ( - <li key={c.id} data-found-row={c.id} className="leading-snug"> - <a href={`#${c.id}`} className="font-medium text-foreground hover:text-brand transition-colors"> - {c.title ?? c.text} - </a> - {c.gist && <span className="text-muted-foreground"> — {c.gist}</span>} - {c.flag && ( - <> - {" "} - <FlagPill flag={c.flag} className="ml-1 align-middle" /> - </> - )} - </li> - ))} - </ul> - </div> - ))} - </section> - )} - - {/* Every claim, with its evidence. */} - <div id="claims" data-report-tier="3" className="flex scroll-mt-20 flex-col gap-8"> - <div className="flex flex-col gap-4"> - <TierMarker depth={3} /> - <h2 className="font-display text-2xl font-semibold tracking-tight text-foreground"> - Every claim, with its evidence - </h2> - {view.method && ( - <div data-report-method="" className="flex flex-col gap-1"> - <h3 className="font-mono text-xs uppercase tracking-[0.16em] text-muted-foreground">How it was checked</h3> - <CitedMarkdown className={proseClass}> - {view.method} - </CitedMarkdown> - </div> - )} - </div> - - {view.sections.length > 1 && ( - <nav aria-label="Sections" className="rounded-lg border border-border p-4 text-sm"> - <ol className="flex list-decimal flex-col gap-1 pl-5 marker:text-muted-foreground"> - {view.sections.map((s) => ( - <li key={s.id}> - <a href={`#${s.id}`} className={textLink}> - {s.title} - </a> - {s.claims.length > 0 && ( - <span className="ml-2 font-mono text-xs text-muted-foreground"> - {s.claims.length} claim{s.claims.length === 1 ? "" : "s"} - </span> - )} - </li> - ))} - </ol> - </nav> - )} - - {view.sections.map((s) => ( - <section key={s.id} id={s.id} data-section={s.id} className="flex scroll-mt-20 flex-col gap-4"> - <h2 className="font-display text-2xl font-semibold tracking-tight text-foreground">{s.title}</h2> - {s.body && ( - <CitedMarkdown className={proseClass}> - {s.body} - </CitedMarkdown> - )} - {s.claims.map((c) => ( - <Claim key={c.id} claim={c} view={view} subjectNoun={subjectNoun} /> - ))} - </section> - ))} - </div> - - {/* The end matter: the documents quoted, the references, the - downloads — the sources slide's place. */} - <div id={REPORT_PAGE_ANCHOR_IDS.end} className="flex scroll-mt-20 flex-col gap-8 empty:hidden"> - {otherSources.length > 0 && ( - <section aria-labelledby="sources-heading" className="flex flex-col gap-3 border-t border-border pt-6"> - <h2 id="sources-heading" className="font-display text-2xl font-semibold tracking-tight text-foreground"> - Sources - </h2> - {otherSources.map((s) => ( - <SourceBlock key={s.id} source={s} label="Quoted" /> - ))} - </section> - )} - - {references.length > 0 && ( - <section id="references" aria-labelledby="references-heading" className="flex scroll-mt-20 flex-col gap-2 border-t border-border pt-6"> - <h2 id="references-heading" className="font-display text-2xl font-semibold tracking-tight text-foreground"> - References - </h2> - <ReferenceList citations={references} addedLabel={`Not in the ${subjectNoun}`} /> - </section> - )} - - {downloads.length > 0 && ( - <p - id="downloads" - data-citation-downloads="" - className="flex scroll-mt-20 flex-wrap items-center gap-x-3 gap-y-1 text-sm text-muted-foreground" - > - <ArrowDownToLine className="size-4" aria-hidden /> - Download: - {downloads.map(([key, label, href]) => ( - <a key={key} href={href} download data-download={key} className={textLink}> - {label} - </a> - ))} - </p> - )} - </div> - </article> - </CitationsProvider> - ); -} diff --git a/export/app/components/reports/ReportHistory.tsx b/export/app/components/reports/ReportHistory.tsx @@ -1,146 +0,0 @@ -import { - reportHistoryViewPath, - type ClaimChange, - type ClaimDiffField, - type DiffSegment, - type ReportHistoryView, - type ReportRevisionView, -} from "yt-dlp-transcript-common/lib/report/revisions"; -import { reportPagePath } from "yt-dlp-transcript-common/lib/report/views"; -import { ReportName, textLink } from "./parts"; - -// A REPORT'S REVISION HISTORY, from its history.json (common/lib/report/revisions.ts): -// how to clone it, then every revision, newest first — its number, date, -// commit and report.json sha256 (the hash every export's footer prints), the -// change summary, and each changed claim as an inline word diff against the -// revision before. - -const FIELD_LABELS: Record<ClaimDiffField, string> = { - title: "Title", - text: "Claim", - verdict: "Verdict", - findings: "Findings", -}; - -const STATUS_LABELS: Record<ClaimChange["status"], string> = { - added: "added", - removed: "removed", - edited: "edited", -}; - -// `2026-03-08T12:00:00Z` → `2026-03-08 12:00 UTC`. -export function revisionDate(iso: string): string { - const m = /^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2})/.exec(iso); - return m ? `${m[1]} ${m[2]} UTC` : iso; -} - -function Diff({ segments }: { segments: DiffSegment[] }) { - return ( - <> - {segments.map((s, i) => - s.op === "ins" ? ( - <ins key={i} data-diff="ins" className="rounded-sm bg-success-soft text-foreground no-underline decoration-success"> - {s.text} - </ins> - ) : s.op === "del" ? ( - <del key={i} data-diff="del" className="rounded-sm bg-destructive-soft text-muted-foreground decoration-destructive"> - {s.text} - </del> - ) : ( - <span key={i}>{s.text}</span> - ), - )} - </> - ); -} - -function ClaimDiff({ change }: { change: ClaimChange }) { - return ( - <div - data-claim-change={change.id} - data-status={change.status} - className="flex flex-col gap-1.5 rounded-md border border-border bg-card px-3 py-2 text-sm" - > - <p className="font-mono text-[11px] text-muted-foreground"> - <span className="text-foreground">{change.id}</span> · {change.section} · {STATUS_LABELS[change.status]} - </p> - {change.fields.map((f) => ( - <p key={f.field} data-field={f.field} className="whitespace-pre-wrap break-words leading-relaxed"> - <span className="mr-2 font-mono text-[10px] uppercase tracking-[0.14em] text-muted-foreground"> - {FIELD_LABELS[f.field]} - </span> - <Diff segments={f.diff} /> - </p> - ))} - </div> - ); -} - -function Revision({ r }: { r: ReportRevisionView }) { - return ( - <li id={`r${r.revision}`} data-revision={r.revision} className="flex scroll-mt-20 flex-col gap-3 border-t border-border pt-5"> - <div className="flex flex-col gap-1"> - <h2 className="font-display text-xl font-semibold tracking-tight text-foreground">Revision {r.revision}</h2> - <p className="font-mono text-xs text-muted-foreground">{revisionDate(r.date)}</p> - </div> - <dl className="grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 font-mono text-xs"> - <dt className="text-muted-foreground">commit</dt> - <dd data-commit={r.commit} className="break-all text-foreground"> - {r.commit} - </dd> - <dt className="text-muted-foreground">report sha256</dt> - <dd data-report-sha256={r.reportSha256} className="break-all text-foreground"> - {r.reportSha256} - </dd> - </dl> - {r.summary.length > 0 && ( - <ul data-revision-summary="" className="flex list-disc flex-col gap-0.5 pl-5 text-sm text-foreground"> - {r.summary.map((line, i) => ( - <li key={i}>{line}</li> - ))} - </ul> - )} - {r.claims.length > 0 && ( - <div className="flex flex-col gap-2"> - {r.claims.map((c) => ( - <ClaimDiff key={c.id} change={c} /> - ))} - </div> - )} - </li> - ); -} - -export default function ReportHistory({ view }: { view: ReportHistoryView }) { - const revisions = [...view.revisions].reverse(); - return ( - <article data-report-history={view.reportId} className="mx-auto flex w-full max-w-3xl flex-col gap-6"> - <header className="flex flex-col gap-3"> - <p className="text-sm"> - <a href={reportPagePath(view.reportId)} className={textLink}> - <ReportName series={view.series} title={view.title} /> - </a> - </p> - <h1 className="font-display text-3xl font-semibold leading-tight tracking-tight text-foreground">Revision history</h1> - <p className="text-sm text-muted-foreground"> - Every edit to this report, newest first. Each revision is a commit in the report&apos;s own git history; its - report sha256 is the hash printed at the foot of the report&apos;s downloads.{" "} - <a href={reportHistoryViewPath(view.reportId)} className={textLink}> - history.json - </a> - </p> - <pre - data-history-clone="" - className="overflow-x-auto rounded-md border border-border bg-muted px-3 py-2 font-mono text-xs text-foreground" - > - <code>git clone {view.clone}</code> - </pre> - </header> - <ol className="flex flex-col gap-6"> - {revisions.map((r) => ( - <Revision key={r.revision} r={r} /> - ))} - </ol> - </article> - ); -} diff --git a/export/app/components/reports/ReportIndex.tsx b/export/app/components/reports/ReportIndex.tsx @@ -1,58 +0,0 @@ -import Link from "next/link"; -import type { ReportIndexView } from "yt-dlp-transcript-common/lib/report/views"; -import { EmptyState, Eyebrow, ReportName, dateLabel } from "./parts"; - -// The report index: `/reports/`, and a cited site's home page when it has more -// than one report. One card per published report, in the site's order -// (site.json `reports`): its name, subtitle and dates -- its counts and tally -// are the report page's. `heading: null` draws no heading (the home page: the -// header already names the site). - -export default function ReportIndex({ - index, - heading = "Reports", - tagline, -}: { - index: ReportIndexView | null; - heading?: string | null; - tagline?: string; -}) { - const reports = index?.reports ?? []; - if (reports.length === 0) { - return <EmptyState title="No reports">This site has not published a report yet.</EmptyState>; - } - return ( - <div className="mx-auto flex w-full max-w-3xl flex-col gap-6"> - {(heading || tagline) && ( - <header className="flex flex-col gap-1"> - {heading && <h1 className="font-display text-3xl font-semibold tracking-tight text-foreground">{heading}</h1>} - {tagline && <p className="text-sm text-muted-foreground">{tagline}</p>} - </header> - )} - <ul data-report-index="" className="flex flex-col gap-4"> - {reports.map((r) => { - const dates = [ - r.published ? `Published ${dateLabel(r.published)}` : null, - r.updated && r.updated !== r.published ? `updated ${dateLabel(r.updated)}` : null, - ] - .filter(Boolean) - .join(" · "); - return ( - <li key={r.id} data-report-entry={r.id}> - <article className="flex flex-col gap-2 rounded-lg border border-border bg-card p-4 sm:p-5"> - {!r.series && <Eyebrow>{r.kind === "factcheck" ? "Fact-check" : "Report"}</Eyebrow>} - <h2 className="font-display text-xl font-semibold leading-snug text-foreground"> - <Link href={r.href} className="hover:text-brand transition-colors"> - <ReportName series={r.series} title={r.title} /> - </Link> - </h2> - {r.subtitle && <p className="text-sm text-muted-foreground">{r.subtitle}</p>} - {dates && <p className="font-mono text-xs text-muted-foreground">{dates}</p>} - </article> - </li> - ); - })} - </ul> - </div> - ); -} diff --git a/export/app/components/reports/parts.tsx b/export/app/components/reports/parts.tsx @@ -1,178 +0,0 @@ -import { Fragment } from "react"; -import Link from "next/link"; -import { ExternalLink } from "lucide-react"; -import { sourceAnchor, subjectMetaParts, type SourceView } from "yt-dlp-transcript-common/lib/report/views"; -import type { SourceArchive } from "yt-dlp-transcript-common/lib/citations/schema"; -import { reportIds } from "../../lib/reports"; - -// Small pieces the report, index and moment pages share. - -// `2026-10-04T12:00:00Z` → `2026-10-04`; a partial date (`2026-10`) as given. -export function dateLabel(v: string | undefined): string | undefined { - if (!v) return undefined; - return /^\d{4}-\d{2}-\d{2}T/.test(v) ? v.slice(0, 10) : v; -} - -export function Eyebrow({ children }: { children: React.ReactNode }) { - return <p className="font-mono text-xs uppercase tracking-[0.18em] text-brand">{children}</p>; -} - -// A report's name as a heading, on its page, in the index and on the history -// page. With a series, the series is its own line in the accent (the tag, -// like a wordmark's lead) and the title the next, in regular weight — both -// inside the heading, so its name reads "<series> <title>"; without one, the -// title alone. -export function ReportName({ series, title }: { series?: string; title: string }) { - if (!series) return <>{title}</>; - return ( - <> - <span data-report-series="" className="block font-semibold text-brand"> - {series} - </span>{" "} - <span className="block font-normal">{title}</span> - </> - ); -} - -export const textLink = - "text-brand underline decoration-brand/40 underline-offset-2 hover:decoration-brand"; - -export function ExternalLinkText({ href, children, title }: { href: string; children: React.ReactNode; title?: string }) { - return ( - <a href={href} target="_blank" rel="noopener noreferrer" title={title} className={`inline-flex items-center gap-1 ${textLink}`}> - {children} - <ExternalLink className="size-3 shrink-0" aria-hidden /> - </a> - ); -} - -// A document a report quotes: its title (linked), byline, note, and its -// archive links in the context the document gave them — collapsed, since a -// long document may carry hundreds. The block is the document's one place on -// the page: its anchor is what a source citation's "from <title>" links to. -// With an `accent`, its left edge wears it, as its sentences' rails do. -export function SourceBlock({ source, label }: { source: SourceView; label: string }) { - const byline = [source.publisher, source.author, dateLabel(source.date)].filter(Boolean).join(" · "); - const n = source.archives.length; - return ( - <div - id={sourceAnchor(source.id)} - data-subject-source={source.id} - className={`flex scroll-mt-20 flex-col gap-1.5 rounded-lg border border-border bg-card p-4 text-sm${source.accent ? " border-l-4" : ""}`} - style={source.accent ? { borderLeftColor: source.accent } : undefined} - > - <p className="font-mono text-[10px] uppercase tracking-[0.16em] text-muted-foreground">{label}</p> - <p className="font-medium leading-snug text-foreground"> - {source.url ? <ExternalLinkText href={source.url}>{source.title}</ExternalLinkText> : source.title} - </p> - {byline && <p className="font-mono text-xs text-muted-foreground">{byline}</p>} - {source.note && <p className="text-xs text-muted-foreground">{source.note}</p>} - {n > 0 && ( - <details data-source-archives={n} className="mt-1 text-xs"> - <summary className="cursor-pointer text-muted-foreground hover:text-foreground"> - {`${n} archive link${n === 1 ? "" : "s"} in context`} - </summary> - <ArchiveList archives={source.archives} className="mt-2" /> - </details> - )} - </div> - ); -} - -// The document under review, under the report's heading: its title linked to -// the document, then "<author> · <publisher> · <date>", then its archive links -// folded away. No label: its left rail, in the document's colour (its -// `accent`, else the border colour) as its sentences' rails below are, says -// whose it is. It is the document's one place on the page, so it carries the -// anchor a citation's "from <title>" links to. -export function SubjectCard({ source }: { source: SourceView }) { - // Each part stays whole on a narrow screen (a date never splits at its dashes). - const meta = subjectMetaParts(source); - const n = source.archives.length; - return ( - <div - id={sourceAnchor(source.id)} - data-subject-source={source.id} - className={`flex min-w-0 scroll-mt-20 flex-col gap-1 rounded-r-md border-l-4 bg-surface py-2.5 pl-3 pr-4 text-sm${source.accent ? "" : " border-border"}`} - style={source.accent ? { borderLeftColor: source.accent } : undefined} - > - <p data-subject-title="" className="font-medium leading-snug text-foreground [overflow-wrap:anywhere]"> - {source.url ? ( - <a - href={source.url} - target="_blank" - rel="noopener noreferrer" - className={`${textLink} after:ml-1 after:inline-block after:text-xs after:content-['↗']`} - > - {source.title} - </a> - ) : ( - source.title - )} - </p> - {meta.length > 0 && ( - <p className="text-xs text-muted-foreground"> - {meta.map((part, i) => ( - <Fragment key={i}> - {i > 0 && " · "} - <span className="whitespace-nowrap">{part}</span> - </Fragment> - ))} - </p> - )} - {n > 0 && ( - <details data-source-archives={n} className="text-xs"> - <summary className="cursor-pointer text-muted-foreground hover:text-foreground"> - {`${n} archive link${n === 1 ? "" : "s"}`} - </summary> - <ArchiveList archives={source.archives} className="mt-2" /> - </details> - )} - </div> - ); -} - -// Archive links, each with the words around it in the document. A document -// may carry hundreds, so a link is text with a CSS arrow, not two inline SVG -// icons apiece. -export function ArchiveList({ archives, className }: { archives: readonly SourceArchive[]; className?: string }) { - return ( - <ul className={`flex flex-col gap-1 ${className ?? ""}`}> - {archives.map((a, i) => ( - <li key={`${i}:${a.url}`} className="flex flex-wrap items-baseline gap-x-2"> - <a href={a.url} target="_blank" rel="noopener noreferrer" className={`${textLink} after:ml-0.5 after:content-['↗']`}> - {a.label} - </a> - {a.context && <span className="text-muted-foreground">— {a.context}</span>} - </li> - ))} - </ul> - ); -} - -export function EmptyState({ title, children }: { title: string; children: React.ReactNode }) { - return ( - <div data-reports-empty="" className="mx-auto flex max-w-2xl flex-col gap-3"> - <h1 className="font-display text-2xl font-semibold text-foreground">{title}</h1> - <p className="text-sm text-muted-foreground">{children}</p> - </div> - ); -} - -// What a corpus-shaped route (search's chat, downloads, duplicates, offline) -// renders on a CITED site, which publishes only its reports and their moments. -// The route still exists in the static build (every route does); it shows -// nothing of the corpus and points at the home page -- the index, or the one -// report. -export function NotOnCitedSite({ title }: { title: string }) { - const one = reportIds().length === 1; - return ( - <EmptyState title={title}> - This site publishes its reports only.{" "} - <Link href="/" className={textLink}> - {one ? "Read the report" : "Read the reports"} - </Link> - . - </EmptyState> - ); -} diff --git a/export/app/downloads/page.tsx b/export/app/downloads/page.tsx @@ -4,7 +4,7 @@ import { ArrowDownToLine, FileText, MessagesSquare } from "lucide-react"; import { currentSite } from "../lib/site"; import { readArchiveManifest } from "../lib/archives"; import { isCitedSite } from "yt-dlp-transcript-common/lib/siteSchema"; -import { NotOnCitedSite } from "../components/reports/parts"; +import { NotOnCitedSite } from "../components/NotOnCitedSite"; export const metadata: Metadata = { title: "Downloads" }; diff --git a/export/app/duplicates/page.tsx b/export/app/duplicates/page.tsx @@ -5,7 +5,7 @@ import PostModal from "yt-dlp-transcript-common/components/PostModal"; import { currentSite } from "../lib/site"; import { DuplicatesClient } from "./DuplicatesClient"; import { isCitedSite } from "yt-dlp-transcript-common/lib/siteSchema"; -import { NotOnCitedSite } from "../components/reports/parts"; +import { NotOnCitedSite } from "../components/NotOnCitedSite"; export const metadata: Metadata = { title: "Duplicates" }; diff --git a/export/app/lib/reportSize.test.ts b/export/app/lib/reportSize.test.ts @@ -5,7 +5,7 @@ import { renderToString } from "react-dom/server"; import { syntheticReport, syntheticReportView } from "../../fixtures/report-site/synthetic"; import { validateReport } from "yt-dlp-transcript-common/lib/report/validate"; import { CLAIM_ARCHIVES_MAX } from "yt-dlp-transcript-common/lib/report/views"; -import ReportArticle from "../components/reports/ReportArticle"; +import ReportArticle from "yt-dlp-transcript-common/components/report/ReportArticle"; // A REPORT PAGE'S SIZE is bounded by what it cites, not by what it repeats. A // report citing one long document many times once carried that document — and diff --git a/export/app/lib/reports.test.ts b/export/app/lib/reports.test.ts @@ -36,7 +36,7 @@ const momentPage = await import("../m/[...moment]/page"); const reportsIndexPage = await import("../reports/page"); const home = await import("../(workspace)/page"); const { headerNavLinks } = await import("./nav"); -const { default: ReportArticle } = await import("../components/reports/ReportArticle"); +const { default: ReportArticle } = await import("yt-dlp-transcript-common/components/report/ReportArticle"); const render = (el: React.ReactElement) => renderToStaticMarkup(el); diff --git a/export/app/lib/reports.ts b/export/app/lib/reports.ts @@ -1,119 +1,27 @@ -import fs from "node:fs"; -import path from "node:path"; -import type { Metadata } from "next"; import { getPaths } from "yt-dlp-transcript-common/lib/paths"; -import { parseMomentKey } from "yt-dlp-transcript-common/lib/citations/moments"; -import { isReportId } from "yt-dlp-transcript-common/lib/report/schema"; -import { - REPORT_HISTORY_FORMAT, - reportHistoryViewPath, - type ReportHistoryView, -} from "yt-dlp-transcript-common/lib/report/revisions"; -import { - MOMENT_INDEX_FORMAT, - MOMENT_PAGE_FORMAT, - MOMENTS_INDEX_PATH, - REPORT_INDEX_FORMAT, - REPORT_PAGE_FORMAT, - REPORTS_INDEX_PATH, - REPORT_FEED_MIME, - momentViewPath, - reportFullTitle, - reportViewPath, - type MomentIndexView, - type MomentPageView, - type ReportIndexView, - type ReportPageView, -} from "yt-dlp-transcript-common/lib/report/views"; +import { createReportReader, reportMetadata } from "yt-dlp-transcript-common/lib/report/reader-server"; +import { SITE_REPORTS_BASE } from "yt-dlp-transcript-common/lib/report/routes"; -// The report and moment views compose's reports stage writes into public/ -// (common/lib/report/views.ts names every file), read at build time like -// lib/archives.ts reads the archive manifest. Every reader is tolerant: a file -// that is absent, unreadable or of another format reads as "none", so a site -// without reports builds exactly as before and a cited site with none renders -// its empty state. Read synchronously — a static export, evaluated once per -// build. +// This site's reports and moments, read from its public dir by the shared +// reader (common/lib/report/reader-server.ts) under the site's base. The +// public dir is resolved on every read: getPaths() is cached on first use, and +// a test sets the environment before it is. -function readView<T extends { format: string }>(urlPath: string, format: T["format"]): T | null { - try { - const file = path.join(getPaths().exportPublicDir, ...urlPath.split("/").filter(Boolean)); - const parsed = JSON.parse(fs.readFileSync(file, "utf8")) as T; - return parsed && parsed.format === format ? parsed : null; - } catch { - return null; - } -} +const reader = createReportReader({ publicDir: () => getPaths().exportPublicDir, base: SITE_REPORTS_BASE }); -export function readReportIndex(): ReportIndexView | null { - const v = readView<ReportIndexView>(REPORTS_INDEX_PATH, REPORT_INDEX_FORMAT); - return v && Array.isArray(v.reports) ? v : null; -} +// Where this site serves its reports: what the shared components are given. +export const REPORTS_BASE = reader.base; +export const readReportIndex = () => reader.readReportIndex(); // Whether this build has a report to link to: drives the header's Reports link. -export function hasReports(): boolean { - return (readReportIndex()?.reports.length ?? 0) > 0; -} - -// The report ids to build pages for, in index order (only well-formed ids: -// each is a path segment). -export function reportIds(): string[] { - return (readReportIndex()?.reports ?? []).map((r) => r.id).filter(isReportId); -} - -export function readReportView(reportId: string): ReportPageView | null { - if (!isReportId(reportId)) return null; - const v = readView<ReportPageView>(reportViewPath(reportId), REPORT_PAGE_FORMAT); - return v && v.id === reportId && Array.isArray(v.sections) ? v : null; -} - -// A report's revision history (/reports/<id>/history/history.json), or null -// when compose published none for it. -export function readReportHistory(reportId: string): ReportHistoryView | null { - if (!isReportId(reportId)) return null; - const v = readView<ReportHistoryView>(reportHistoryViewPath(reportId), REPORT_HISTORY_FORMAT); - return v && v.reportId === reportId && Array.isArray(v.revisions) && v.revisions.length > 0 ? v : null; -} - +export const hasReports = () => reader.hasReports(); +export const reportIds = () => reader.reportIds(); +export const readReportView = (reportId: string) => reader.readReportView(reportId); +export const readReportHistory = (reportId: string) => reader.readReportHistory(reportId); // The build's one report, when it publishes exactly one: a cited site's home // page IS that report. -export function onlyReportView(): ReportPageView | null { - const ids = reportIds(); - return ids.length === 1 ? readReportView(ids[0]) : null; -} - -// A report's page metadata — its page's, and a one-report cited site's home's, -// so the tab reads the same on both: the title as one line names it -// (`<series>: <title>`, the layout's template adds the site), the subtitle as -// the description, and its timeline's feeds when it publishes them (a -// `<link rel="alternate">` each, by absolute URL: the layout sets no -// metadataBase). -export function reportMetadata(view: ReportPageView): Metadata { - const title = reportFullTitle(view); - return { - title, - ...(view.subtitle ? { description: view.subtitle } : {}), - ...(view.feeds - ? { - alternates: { - types: { - [REPORT_FEED_MIME.rss]: [{ url: view.feeds.rss, title }], - [REPORT_FEED_MIME.json]: [{ url: view.feeds.json, title }], - }, - }, - } - : {}), - }; -} - -// The moment keys to build pages for (only keys exactly as momentKey spells -// them: each segment is a path segment of a page written to disk). -export function momentKeys(): string[] { - const v = readView<MomentIndexView>(MOMENTS_INDEX_PATH, MOMENT_INDEX_FORMAT); - return (Array.isArray(v?.moments) ? v.moments : []).filter((k) => parseMomentKey(k) !== null); -} +export const onlyReportView = () => reader.onlyReportView(); +export const momentKeys = () => reader.momentKeys(); +export const readMomentView = (key: string) => reader.readMomentView(key); -export function readMomentView(key: string): MomentPageView | null { - if (!parseMomentKey(key)) return null; - const v = readView<MomentPageView>(momentViewPath(key), MOMENT_PAGE_FORMAT); - return v && v.key === key ? v : null; -} +export { reportMetadata }; diff --git a/export/app/m/[...moment]/page.tsx b/export/app/m/[...moment]/page.tsx @@ -1,7 +1,7 @@ import type { Metadata } from "next"; import { MOMENT_PLACEHOLDER_KEY } from "yt-dlp-transcript-common/lib/report/views"; -import MomentArticle from "../../components/reports/MomentArticle"; -import { EmptyState } from "../../components/reports/parts"; +import MomentArticle from "yt-dlp-transcript-common/components/report/MomentArticle"; +import { EmptyState } from "yt-dlp-transcript-common/components/report/parts"; import { momentKeys, readMomentView } from "../../lib/reports"; // /m/<channel>/<id>/<start>-<end>/ (a span) and /m/<channel>/<id>/ (a post): diff --git a/export/app/offline/page.tsx b/export/app/offline/page.tsx @@ -6,7 +6,7 @@ import { postsVisibleTo } from "yt-dlp-transcript-common/lib/postsVisibility"; import { currentSite } from "../lib/site"; import { OfflineManager, type OfflineChannel } from "../components/OfflineManager"; import { isCitedSite } from "yt-dlp-transcript-common/lib/siteSchema"; -import { NotOnCitedSite } from "../components/reports/parts"; +import { NotOnCitedSite } from "../components/NotOnCitedSite"; export const metadata: Metadata = { title: "Offline", diff --git a/export/app/reports/[reportId]/history/page.tsx b/export/app/reports/[reportId]/history/page.tsx @@ -1,8 +1,8 @@ import type { Metadata } from "next"; import { REPORT_PLACEHOLDER_ID, reportFullTitle } from "yt-dlp-transcript-common/lib/report/views"; -import ReportHistory from "../../../components/reports/ReportHistory"; -import { EmptyState } from "../../../components/reports/parts"; -import { readReportHistory, reportIds } from "../../../lib/reports"; +import ReportHistory from "yt-dlp-transcript-common/components/report/ReportHistory"; +import { EmptyState } from "yt-dlp-transcript-common/components/report/parts"; +import { REPORTS_BASE, readReportHistory, reportIds } from "../../../lib/reports"; // /reports/<reportId>/history/: the report's revisions, from // /reports/<reportId>/history/history.json. Static: built for every published @@ -28,5 +28,5 @@ export default async function ReportHistoryPage({ params }: Params) { if (!view) { return <EmptyState title="No history">This report has no published revision history.</EmptyState>; } - return <ReportHistory view={view} />; + return <ReportHistory view={view} base={REPORTS_BASE} />; } diff --git a/export/app/reports/[reportId]/page.tsx b/export/app/reports/[reportId]/page.tsx @@ -1,8 +1,8 @@ import type { Metadata } from "next"; import { REPORT_PLACEHOLDER_ID } from "yt-dlp-transcript-common/lib/report/views"; -import ReportArticle from "../../components/reports/ReportArticle"; -import { EmptyState } from "../../components/reports/parts"; -import { readReportView, reportIds, reportMetadata } from "../../lib/reports"; +import ReportArticle from "yt-dlp-transcript-common/components/report/ReportArticle"; +import { EmptyState } from "yt-dlp-transcript-common/components/report/parts"; +import { REPORTS_BASE, readReportView, reportIds, reportMetadata } from "../../lib/reports"; // /reports/<reportId>/: one report, from /reports/<reportId>/page.json. // Static: every published report is listed, nothing else resolves. A site with @@ -32,5 +32,5 @@ export default async function ReportPage({ params }: Params) { </EmptyState> ); } - return <ReportArticle view={view} />; + return <ReportArticle view={view} base={REPORTS_BASE} />; } diff --git a/export/app/reports/page.tsx b/export/app/reports/page.tsx @@ -1,8 +1,8 @@ import type { Metadata } from "next"; -import ReportIndex from "../components/reports/ReportIndex"; +import ReportIndex from "yt-dlp-transcript-common/components/report/ReportIndex"; import Link from "next/link"; import { isCitedSite } from "yt-dlp-transcript-common/lib/siteSchema"; -import { textLink } from "../components/reports/parts"; +import { textLink } from "yt-dlp-transcript-common/components/report/parts"; import { readReportIndex, reportIds } from "../lib/reports"; import { currentSite } from "../lib/site"; import { instanceMode } from "../lib/mode";