import { cache } from "react"; import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { getSite, isValidSiteId, listSiteIds, type Site, } from "yt-dlp-transcript-common/lib/site"; // The layout and every tab page need the site — the layout for the title, // the page for its own section. React cache() dedupes them into ONE read per // request (the channel routes do the same, channelConfigCache.ts). Returns // null for an id that is malformed or has no site.json, so the caller's // notFound() is the one 404 for /sites/ and every tab under it. // Request-scoped, not a process cache: a site renamed by the form on the // previous request is read fresh on the next one. export const getSiteCached = cache((siteId: string): Site | null => { const paths = getPaths(); if (!isValidSiteId(siteId) || !listSiteIds(paths).includes(siteId)) return null; return getSite(siteId, paths); });