// THE SOCIAL TEXT (release 29 G2): what a cut's promotion posts say, as files // the operator copies from -- `out/x.txt` and `out/bluesky.txt`, composed by // CODE from `publish.x` / `publish.bluesky` `{ post, thread? }` (drafted by // the social task, its link already under the first post, or written by // hand). TEXT ONLY: nothing here, or anywhere, posts it. // // // // — 2/3 — // // // — 3/3 — // // // The `— k/n —` lines are not part of any post: they say where one ends. // How a post is counted is common's (lib/report/social.mjs); the lengths are // the manifest's to keep within (validatePublish), so this composes what is // there and says nothing about it. // // PURE: no fs. build-video.mjs writes the files (wherever it writes // out/youtube.txt), and so does the chain's social draft. import { SOCIAL_PLATFORMS } from "yt-dlp-transcript-common/lib/report/social.mjs"; export { SOCIAL_PLATFORMS }; const text = (s) => (typeof s === "string" ? s.trim() : ""); /** A platform's posts in order: the first, then the thread's. Empty when there is no first post. */ export function socialPosts(value) { const post = text(value?.post); if (!post) return []; return [post, ...(Array.isArray(value?.thread) ? value.thread.map(text).filter(Boolean) : [])]; } /** * The file's text for one platform's `{ post, thread? }`, or null when it has * no first post. * * @param {{ post?: string, thread?: string[] } | null | undefined} value * @returns {string | null} */ export function composeSocialText(value) { const posts = socialPosts(value); if (!posts.length) return null; if (posts.length === 1) return `${posts[0]}\n`; return `${posts.map((p, i) => (i === 0 ? p : `— ${i + 1}/${posts.length} —\n${p}`)).join("\n\n")}\n`; } /** The file a platform's text is written to, in the project's `out/`. */ export const socialTextName = (platform) => `${platform}.txt`; /** * Every platform's file for a manifest: `[{ platform, name, text }]`, `text` * null when the manifest has no post for it (an old file is then removed by * the writer, so out/ never shows a post the manifest no longer has). */ export function socialTexts(manifest) { return SOCIAL_PLATFORMS.map((platform) => ({ platform, name: socialTextName(platform), text: composeSocialText(manifest?.publish?.[platform]) })); }