import { readFile, stat } from "node:fs/promises"; import path from "node:path"; import CopyButton from "@/components/CopyButton"; import { fmtAgo } from "@/lib/format"; import { youtubePreview, youtubeTextName } from "umtool-report-to-video/youtube"; // The upload's text (release 28 M6): what the build wrote to // out/youtube.txt — the title, the summary, the chapters and the sources — // or, before a build, the same text composed from the manifest without the // chapters. Shown with Copy. Nothing when the cut has no publish.youtube and // no built text. type Props = { dir: string; manifest: Record }; export default async function YoutubeSection({ dir, manifest }: Props) { const file = path.join(dir, "out", youtubeTextName("sourced")); const built = await readFile(file, "utf8").catch(() => null); const mtimeMs = built === null ? null : await stat(file).then((s) => s.mtimeMs, () => null); const preview = youtubePreview(manifest); const text = built ?? preview.text; if (!text) return null; const yt = (manifest.publish as { youtube?: { title?: string; description?: string } } | undefined)?.youtube; // The built text starts with the title and the summary as they were then. const head = [yt?.title?.trim(), yt?.description?.trim()].filter(Boolean).join("\n\n"); const stale = built !== null && !!head && !built.startsWith(head); const drafted = (manifest.drafted as Record | undefined)?.["publish.youtube"]; return (

youtube

{built !== null ? `out/${youtubeTextName("sourced")}${mtimeMs ? `, built ${fmtAgo(mtimeMs)}` : ""}${stale ? " — the title or summary has changed since: rebuild" : ""}` : `preview — ${preview.note}`} {drafted ? ` · drafted by ${drafted.model ?? "a model"}` : ""}
        {text}
      
); }