import { stat } from "node:fs/promises"; import path from "node:path"; import CopyButton from "@/components/CopyButton"; import { Panel } from "@/components/ui/panel"; import { fmtAgo } from "@/lib/format"; import { SOCIAL_LIMITS, SOCIAL_NAMES, socialLength, type SocialPlatform } from "yt-dlp-transcript-common/lib/report/social.mjs"; import { SOCIAL_PLATFORMS, composeSocialText, socialPosts, socialTextName } from "umtool-report-to-video/social"; import RedraftSocial from "./RedraftSocial"; // The promotion posts (release 29 G2): `publish.x` and `publish.bluesky`, the // first post (its link under it, added by code) and the thread under it, each // with its length as its platform counts it (X: a link is 23; Bluesky: // graphemes). Copy takes what out/.txt holds -- the same text, // composed from the manifest. TEXT ONLY: nothing here posts. Nothing when // the cut has neither post. // // The link under a first post is fixed when it is drafted. When the cut's // `publish.videoUrl` is set and a post does not carry it (it was drafted // before, linking the article or nothing), the section says so and offers a // re-draft on the iteration the cut was made from (review fix, release 29). type Props = { dir: string; manifest: Record; iteration?: { article: string; n: number } | null }; type Value = { post?: string; thread?: string[] }; export default async function SocialPostSection({ dir, manifest, iteration = null }: Props) { const publish = (manifest.publish ?? {}) as Partial>; const drafted = (manifest.drafted ?? {}) as Record; const platforms = (SOCIAL_PLATFORMS as readonly SocialPlatform[]).filter((p) => socialPosts(publish[p]).length > 0); if (!platforms.length) return null; const written = Object.fromEntries( await Promise.all(platforms.map(async (p) => [p, await stat(path.join(dir, "out", socialTextName(p))).then((s) => s.mtimeMs, () => null)] as const)), ) as Record; const videoUrl = typeof (manifest.publish as { videoUrl?: unknown } | undefined)?.videoUrl === "string" ? String((manifest.publish as { videoUrl: string }).videoUrl).trim() : ""; const stale = /^https?:\/\/\S+$/i.test(videoUrl) ? platforms.filter((p) => !String(publish[p]?.post ?? "").includes(videoUrl)) : []; const yours = stale.filter((p) => !drafted[`publish.${p}`]); return ( text only — copy it, nothing is posted}> {stale.length > 0 && (

The {stale.map((p) => SOCIAL_NAMES[p]).join(" and ")} post{stale.length > 1 ? "s link" : " links"} the old address, not the video ({videoUrl}): the link is set when a post is drafted. {yours.length > 0 ? ` ${yours.map((p) => SOCIAL_NAMES[p]).join(" and ")}: yours — edit it, a re-draft never replaces it.` : ""} {iteration && yours.length < stale.length && }

)}
{platforms.map((p) => { const posts = socialPosts(publish[p]); const text = composeSocialText(publish[p]) ?? ""; const by = drafted[`publish.${p}`]; return (

{SOCIAL_NAMES[p]}

{written[p] !== null ? `out/${socialTextName(p)}, written ${fmtAgo(written[p]!)}` : "not written to out/ yet"} {by ? ` · drafted by ${by.model ?? "a model"}` : ""} 1 ? " and its thread" : ""}`} />
    {posts.map((t, i) => { const n = socialLength(p, t); const over = n > SOCIAL_LIMITS[p]; return (
  1. {t}
    {posts.length > 1 ? `${i + 1}/${posts.length} · ` : ""} {n}/{SOCIAL_LIMITS[p]} {p === "bluesky" ? "graphemes" : "as X counts"} {over ? " — over the limit" : ""}
  2. ); })}
); })}
); }