// WHAT A PUBLIC HOMEPAGE BUILD MAY NOT HOLD (release 26 A4, // plans/reports-on-homepage.md, "Two homepage builds"). // // The homepage builds twice from one source: the PUBLIC build carries the // published articles whose report.json says `audience: "public"`, the PRIVATE // one (`archilyzer build homepage --private`, homepage/out-private) every // published article, and is never deployed. compose stamps each build in // `homepage-build.json` (bin/compose-homepage.ts). This audit is the second // line, asked of homepage/out by the build, the deploy stage and the status // (lib/builtExport.ts builtHomepageProblem): // // - a build stamped `audience: "private"` is never deployed; // - an article under out/articles// must be one the article store marks // public now (report.json `audience`, absent = private) — one made private, // or gone, since the build is refused until the homepage is rebuilt; // - a moment under out/m/ may be cited only by such articles (its page names // every citing article: a private one's title would leak through it); // - while `social.x.visibility` is "private", no X channel's post — its // moment page or its captured media — is in the build, as a public site's // never is (lib/postsVisibility.ts). // // The store and the channel configs are read only when the caller passes the // paths; without them the stamp alone is checked. Synchronous: a status page // asks it. import { existsSync, readdirSync, readFileSync } from "node:fs"; import path from "node:path"; import type { Paths } from "./paths"; import { anyPostsPlatformPrivate, withheldPostsPlatform } from "./postsVisibility"; import { ARTICLES_REPORTS_BASE, reportBaseDir } from "./report/routes"; export const HOMEPAGE_BUILD_STAMP = "homepage-build.json"; export type HomepageAuditOptions = { paths?: Pick; // `social.x.visibility`; asked only with `paths`. settings?: { social?: { x?: { visibility?: unknown }; instagram?: { visibility?: unknown } } }; }; const readJson = (file: string): unknown => { try { return JSON.parse(readFileSync(file, "utf8")); } catch { return null; } }; const dirs = (dir: string): string[] => { try { return readdirSync(dir, { withFileTypes: true }) .filter((e) => e.isDirectory()) .map((e) => e.name) .sort(); } catch { return []; } }; // Every moment.json under out/m/, by key. function momentFiles(outDir: string): { key: string; file: string }[] { const out: { key: string; file: string }[] = []; const walk = (dir: string, rel: string[]) => { if (existsSync(path.join(dir, "moment.json"))) out.push({ key: rel.join("/"), file: path.join(dir, "moment.json") }); for (const d of dirs(dir)) walk(path.join(dir, d), [...rel, d]); }; walk(path.join(outDir, "m"), []); return out; } // The stamp's audience, when the build carries one. export function homepageBuildAudience(outDir: string): string | null { const stamp = readJson(path.join(outDir, HOMEPAGE_BUILD_STAMP)) as { audience?: unknown } | null; return typeof stamp?.audience === "string" ? stamp.audience : null; } // The first reason `outDir` may not be deployed as the public homepage, or null. export function homepageAudienceProblem(outDir: string, opts: HomepageAuditOptions = {}): string | null { if (homepageBuildAudience(outDir) === "private") { return `${outDir} holds a private homepage build (its ${HOMEPAGE_BUILD_STAMP} says "audience": "private"), which is never deployed`; } const paths = opts.paths; if (!paths) return null; const articlesDir = path.join(outDir, reportBaseDir(ARTICLES_REPORTS_BASE)); const built = dirs(articlesDir).filter((id) => existsSync(path.join(articlesDir, id, "page.json"))); const isPublic = new Map(); const publicNow = (id: string) => { if (!isPublic.has(id)) { const doc = readJson(path.join(paths.articlesDir, id, "report.json")) as { audience?: unknown } | null; // lib/report/registry.ts articleAudience: absent = private. isPublic.set(id, doc?.audience === "public"); } return isPublic.get(id)!; }; for (const id of built) { if (!publicNow(id)) { return `the homepage build carries the article "${id}", which is not public (its report.json's audience) — rebuild the homepage`; } } // A posts platform that is private now (X by its setting; Instagram unless // set public): which one withholds a channel, or null. const settings = opts.settings ?? {}; const xPrivate = anyPostsPlatformPrivate(settings); const configs = new Map(); const withheld = (slug: string) => { if (!configs.has(slug)) { configs.set(slug, withheldPostsPlatform(readJson(path.join(paths.channelsDir, slug, "config.json")) as never, settings)); } return configs.get(slug)!; }; const isX = (slug: string) => withheld(slug) === "x"; const isInstagram = (slug: string) => withheld(slug) === "instagram"; const articlePrefix = ARTICLES_REPORTS_BASE; for (const m of momentFiles(outDir)) { const view = readJson(m.file) as { citedIn?: { href?: unknown }[] } | null; for (const c of view?.citedIn ?? []) { const href = typeof c.href === "string" ? c.href : ""; const id = href.startsWith(articlePrefix) ? href.slice(articlePrefix.length).split(/[/#]/)[0] : ""; if (!id || !publicNow(id)) { return `the homepage build's moment ${m.key} is cited by ${id ? `the article "${id}", which is not public` : `"${href}", which is no public article`} — rebuild the homepage`; } } if (xPrivate && isX(m.key.split("/")[0])) { return `the homepage build's moment ${m.key} is an X post, and X posts are private (social.x.visibility) — rebuild the homepage`; } if (xPrivate && isInstagram(m.key.split("/")[0])) { return `the homepage build's moment ${m.key} is an Instagram post, and Instagram posts are private (social.instagram.visibility) — rebuild the homepage`; } } if (xPrivate) { for (const slug of dirs(path.join(outDir, "media", "posts"))) { if (isX(slug)) { return `the homepage build carries media/posts/${slug}/, an X channel's captures, and X posts are private (social.x.visibility) — rebuild the homepage`; } if (isInstagram(slug)) { return `the homepage build carries media/posts/${slug}/, an Instagram channel's captures, and Instagram posts are private (social.instagram.visibility) — rebuild the homepage`; } } } return null; }