import type { Metadata } from "next"; import Link from "next/link"; import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { formatBytes } from "yt-dlp-transcript-common/lib/format"; import { REPORT_EXPORT_FILENAMES, REPORT_EXPORT_FORMATS, } from "yt-dlp-transcript-common/lib/report/views"; import { ArticleRowActions } from "../components/ArticleRowActions"; import { ArticleVideoControl } from "../components/ArticleVideoControl"; import { ExportArticlesButton, PrepareArticlesMediaButton } from "../components/ArticlesJobButtons"; import { FetchMissingEvidenceButton } from "../components/FetchMissingEvidenceButton"; import { publishRefusal, reportMediaSummary, type ReportMediaSummary } from "../lib/reportList"; import type { ReportExportsRow } from "../lib/reportListServer"; import { latestArticlesJob, readArticleExports, readArticleRows, readArticlesMediaIndex, type ArticleRow, } from "../lib/articlesServer"; export const dynamic = "force-dynamic"; export const metadata: Metadata = { title: "Articles — Sites" }; // THE ARTICLES (release 26): every article directory under // `transcripts/reports/`, published by the project homepage — not by a site — // in `reports/index.json`'s order, then the drafts. Each article's audience // says which homepage build carries it: the public one only "public" // articles, the private (local-only) one every published article. Publish, // unpublish, reorder and the audience are written through the article // registry (lib/report/registry.ts), as `pnpm ops articles-config` writes // them. The evidence media and the exports are a site's Reports tab's, over // the articles, on the same queue. A site's own pages stay on its Reports tab. // // A static segment beside /sites/[siteId]: a site named "articles" is not // reachable here, as one named "new" is not. export default async function ArticlesPage() { const paths = getPaths(); const { rows, indexError } = await readArticleRows(paths); const published = rows.filter((r) => r.position !== null).map((r) => r.id); const [mediaIndex, exportRows, lastJob, lastExportJob] = await Promise.all([ readArticlesMediaIndex(paths), readArticleExports(paths, published), latestArticlesJob(paths, "reports-prepare"), latestArticlesJob(paths, "reports-export"), ]); const publicCount = rows.filter((r) => r.position !== null && r.audience === "public").length; return (
Sites / Articles

Articles

{published.length} published ({publicCount} public), {rows.length - published.length} draft {rows.length - published.length === 1 ? "" : "s"}

{indexError && (

{indexError}

)}
{rows.length === 0 ? (

No articles yet. Put one at reports/<articleId>/report.json.

) : ( )}

Evidence media

Last prepare job:{" "} {lastJob ? ( {lastJob.id} ) : ( "none among recent jobs" )} {lastJob && <> ({lastJob.status})}

{mediaIndex ? ( ) : (

Not prepared yet.

)}

Exports

Last export job:{" "} {lastExportJob ? ( {lastExportJob.id} ) : ( "none among recent jobs" )} {lastExportJob && <> ({lastExportJob.status})}

{exportRows.length === 0 ? (

No published article to export.

) : (
    {exportRows.map((row) => ( ))}
)}
); } const STATUS_TEXT: Record = { ok: "No problems", problems: "Has problems", invalid: "Not a valid report", missing: "Missing", }; function ArticleListItem({ row, publishedCount }: { row: ArticleRow; publishedCount: number }) { const dates = [ row.publishedDate ? `published ${row.publishedDate}` : null, row.updatedDate ? `updated ${row.updatedDate}` : null, ].filter(Boolean); return (
  • {row.position !== null && {row.position + 1}. } {row.title ?? row.id} {row.subtitle && {row.subtitle}} {row.id} {row.kind && <> · {row.kind === "factcheck" ? "fact-check" : "sweep"}} {dates.length > 0 && <> · {dates.join(", ")}}
    {row.position !== null ? "Published" : "Draft"} {" · "} {row.audience === "public" ? "Public" : "Private"}
    {(row.status === "ok" || row.status === "problems") && (

    {row.sections} section{row.sections === 1 ? "" : "s"} · {row.claims} claim {row.claims === 1 ? "" : "s"} · {row.citations} citation{row.citations === 1 ? "" : "s"}

    )} {row.status !== "missing" && } {row.problems.length === 0 ? ( {STATUS_TEXT[row.status]} ) : (
    {STATUS_TEXT[row.status]} — {row.problems.length} problem{row.problems.length === 1 ? "" : "s"}
      {row.problems.map((p, i) => (
    • {p.path && {p.path}} {p.path && ": "} {p.message}
    • ))}
    )}
  • ); } function MediaSummary({ summary }: { summary: ReportMediaSummary }) { return (

    Prepared {new Date(summary.preparedAt).toLocaleString()}: {summary.moments} moment {summary.moments === 1 ? "" : "s"} {summary.momentsByKind.length > 0 && <> ({summary.momentsByKind.map((k) => `${k.count} ${k.kind}`).join(", ")})} , {formatBytes(summary.totalBytes)}.

    {summary.problems.length === 0 ? (

    No problems.

    ) : (
    {summary.problems.length} problem{summary.problems.length === 1 ? "" : "s"}:{" "} {summary.problemsByKind.map((k) => `${k.count} ${k.kind}`).join(", ")}
      {summary.problems.map((p, i) => (
    • {p.kind} {p.moment ?? p.report ?? "?"} {p.citations && p.citations.length > 0 && ( (cited by {p.citations.join(", ")}) )} : {p.message}
    • ))}
    )}
    ); } function ExportSummary({ row }: { row: ReportExportsRow }) { const { manifest, publishable } = row; return (
  • {row.reportId}{" "} {manifest ? `exported ${new Date(manifest.exportedAt).toLocaleString()}` : "not exported yet"}

    {manifest?.revision && (

    Revision {manifest.revision.revision} · {manifest.revision.date.slice(0, 10)} ·{" "} {manifest.revision.commit.slice(0, 12)}

    )} {manifest && ( )} {[...(manifest?.notes ?? []), ...publishable.notes].map((note, i) => (

    {note}

    ))}
  • ); }