// `umtool posts slurs` -- THE SLUR FILTER of a cut's post items // (umtool-report-to-video/post-slurs.mjs; umtool/docs/knobs.md, "The slur // filter"): what it would mask, and its knobs. // // umtool posts slurs
[ls] what the cut would mask: per slur, per post, and each read's state // umtool posts slurs
on | off the filter (off: the cut is the uncensored one) // umtool posts slurs
level strong|all only the strong slurs, or the mild ones too // umtool posts slurs
visual blackout|placeholder // umtool posts slurs
voice skip|beep|placeholder // umtool posts slurs
add edges …` */
export async function slursCommand(project, rest, { json = false, off = false, out = (s) => console.log(s) } = {}) {
const [sub = "ls", arg] = rest;
const write = async (change) => withEditNotes(project, async () => updatePostSlurs(project.dir, change, { token: await manifestToken(project.dir) }));
const said = async (change, line) => {
const { result } = await write(change);
// The edges by their masks (edgeShown): a write's JSON never prints a slur it edged.
const shown = Array.isArray(result.slurs?.edges) ? { ...result.slurs, edges: result.slurs.edges.map((w) => edgeShown(w, result.slurs)) } : result.slurs;
out(json ? JSON.stringify({ ok: true, slurs: shown, token: result.token }, null, 2) : `${project.id}: ${line}`);
return 0;
};
const one = (list, what) => {
if (!arg || !list.includes(arg)) throw new SlursError(`posts slurs ${sub} takes ${list.join(" or ")}${arg ? ` (not ${arg})` : ""}`);
return arg;
};
if (sub === "on") return said({ set: { on: null } }, "the slur filter is on (the default): the cut publishes its post items censored");
if (sub === "off") return said({ set: { on: false } }, "the slur filter is OFF: this is the uncensored cut (the redaction and censored attachments stay on)");
if (sub === "level") return said({ set: { level: one(SLUR_LEVELS) === SLURS_DEFAULTS.level ? null : arg } }, `level ${arg}: ${arg === "strong" ? "only the strong slurs are masked" : "strong and mild slurs are masked"}`);
if (sub === "visual") return said({ set: { visual: one(SLUR_VISUALS) === SLURS_DEFAULTS.visual ? null : arg } }, `visual ${arg}: ${arg === "blackout" ? "a solid bar, as a redacted word" : "a dark pill with the masked form"}`);
if (sub === "voice") return said({ set: { voice: one(SLUR_VOICES) === SLURS_DEFAULTS.voice ? null : arg } }, `voice ${arg}: ${arg === "skip" ? "left out of a synthesized read" : arg === "beep" ? "said, with a beep over it (the take's word timings)" : "its stand-in said in its place"}`);
if (sub === "add" || sub === "except" || sub === "remove") {
if (!arg || !/^[A-Za-z][A-Za-z-]{1,39}$/.test(arg)) throw new SlursError(`posts slurs ${sub} takes a word (letters, 2–40)`);
const what = sub === "add" ? "masked in this cut" : sub === "except" ? "never masked in this cut" : "off the project's lists";
return said({ [sub]: arg }, `${maskOfOwnWord(arg)} is ${what}`);
}
if (sub === "edges") {
if (!arg || !/^[A-Za-z][A-Za-z-]{1,39}$/.test(arg)) throw new SlursError("posts slurs edges takes a word, a slur's id or one of its forms (letters, 2–40)");
const m = await readManifest(project.dir);
if (!m) throw new SlursError(`${project.id} has no manifest`);
const cfg = isObj(m.render?.posts?.slurs) ? m.render.posts.slurs : {};
if (!off && !edgeEntryOf(arg, cfg)) throw new SlursError(`posts slurs edges: ${maskOfOwnWord(arg)} names no slur on the list or of the project's own (add it first)`);
const shown = edgeShown(arg, cfg);
return said(off ? { unedge: arg } : { edge: arg }, off ? `${shown}: back to the first-letter mask` : `${shown}: edge-masked -- every form its first letter, stars and its last letter, in the case written`);
}
if (sub !== "ls") throw new SlursError(`posts slurs: ls, on, off, level, visual, voice, add, except, remove or edges (not ${sub})`);
const manifest = await readManifest(project.dir);
if (!manifest) throw new SlursError(`${project.id} has no manifest`);
const { slurs: s, report, reads } = slursListing(manifest);
const cfg = isObj(manifest.render?.posts?.slurs) ? manifest.render.posts.slurs : {};
if (json) {
out(JSON.stringify({ ok: true, on: s.on, level: s.level, visual: s.visual, voice: s.voice, listed: s.entries.length, add: (cfg.add ?? []).length, except: (cfg.except ?? []).length, edges: (cfg.edges ?? []).map((w) => edgeShown(w, cfg)), total: report.total, bySlur: report.bySlur, posts: report.posts, reads }, null, 2));
return 0;
}
out(
`${project.id}: the slur filter is ${s.on ? "ON" : "OFF (the uncensored cut)"} -- level ${s.level}, visual ${s.visual}, voice ${s.voice}` +
` (${s.entries.length} slur(s) listed${cfg.add?.length ? `, ${cfg.add.length} of its own` : ""}${cfg.except?.length ? `, ${cfg.except.length} excepted` : ""})`,
);
if (cfg.edges?.length) out(` edges: ${cfg.edges.map((w) => edgeShown(w, cfg)).join(", ")} (first letter, stars, last letter)`);
if (!report.total) {
out(" no post item of the cut holds a slur on the list");
return 0;
}
out(` it ${s.on ? "masks" : "would mask"} ${report.total} word(s) in ${report.posts.length} post item(s):`);
const rows = Object.entries(report.bySlur).sort((a, b) => b[1].n - a[1].n);
// A project's own word is named by its mask alone (its id would spell it).
for (const [id, b] of rows) out(` ${b.mask.padEnd(10)} ${(b.added ? "(its own)" : id).padEnd(18)} ×${String(b.n).padEnd(4)} in ${b.posts.length} post(s): ${b.posts.slice(0, 8).join(", ")}${b.posts.length > 8 ? ", …" : ""}`);
out(" per post item:");
for (const p of report.posts) out(` ${p.id.padEnd(22)} ${Object.entries(p.hits).map(([id, n]) => `${report.bySlur[id]?.mask ?? id} ×${n}`).join(", ")} (${p.where.join(", ")})`);
if (reads.length) {
const need = reads.filter((r) => r.needs);
out(` the reads: ${reads.length} narrated post(s) hold a slur in their read -- ${reads.filter((r) => r.covered).length} covered, ${need.length} need word timings`);
for (const r of reads) out(` ${r.id.padEnd(22)} ${r.needs ? `NEEDS WORD TIMINGS (a censored build refuses it): umtool posts narrate ${project.id} ${r.id} --words` : `${r.covered}${r.spans ? ` (${r.spans} span(s))` : ""}`}`);
}
return 0;
}