import fs from "node:fs"; import path from "node:path"; import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import type { ArchiveManifest } from "yt-dlp-transcript-common/lib/archiveOptions"; // The archive manifest compose-site.ts writes into public/archives at build // time. Absent when the build didn't generate archives (dev, or opted out), so // the Downloads page and its Header/Footer links all key off this presence. // Read synchronously — this is a static export, evaluated once per build. export function readArchiveManifest(): ArchiveManifest | null { try { const file = path.join( getPaths().exportPublicDir, "archives", "manifest.json", ); const parsed = JSON.parse(fs.readFileSync(file, "utf8")) as ArchiveManifest; if (!parsed || !Array.isArray(parsed.entries)) return null; return parsed; } catch { return null; } } // Whether this site has at least one downloadable archive to link to — either // served locally (not oversize) or uploaded to overflow storage (has a `url`). // Drives showing the Downloads nav/footer entry. export function hasArchives(): boolean { const manifest = readArchiveManifest(); return !!manifest && manifest.entries.some((e) => !e.oversize || e.url); }