import { getPaths } from "yt-dlp-transcript-common/lib/paths"; import { getSite, defaultSiteId, listSiteIds, parseSite, type Site, } from "yt-dlp-transcript-common/lib/site"; import { getHomepageConfig, resolveHomepageSocialLinks, } from "yt-dlp-transcript-common/lib/homepage"; import { PROJECT_WORDMARK_LEAD } from "yt-dlp-transcript-common/lib/project"; // The export app builds ONE site at a time, selected by the SITE_ID env var // (set by the build:site script). At dev time SITE_ID may be unset; we then // fall back to the lone configured site so `next dev` just works for a // single-site install. Branding, social links, tagline and the charts/search // data all derive from this site. // // When nothing is selected and no (or multiple) sites exist, we synthesize a // neutral default rather than throwing — otherwise `next dev` would crash on // boot before any site is configured (and the e2e harness couldn't start the // server). A real build always passes SITE_ID, so production is unaffected. // In hub mode the app has no single Site — its branding is the instance-level // HomepageConfig ("Archilyzer"). Synthesize a Site from it so layout/manifest/ // Header/Footer keep working unchanged (no channels/groups; the hub ships a PWA // by default; its wordmark splits as the project's own). Read INSTANCE_MODE // directly here rather than importing mode.ts, which imports currentSite() // (would be a cycle). function hubSite(): Site { const cfg = getHomepageConfig(); return parseSite("hub", { siteTitle: cfg.siteTitle, siteDescription: cfg.siteDescription, headerTitle: cfg.headerTitle, // "Archi" + "lyzer". Dropped by the parse (whole title heavy) if the // operator's homepage.json retitles the header to something it does not // start. wordmarkLead: PROJECT_WORDMARK_LEAD, homeTagline: cfg.homeTagline, ...(cfg.siteUrl ? { siteUrl: cfg.siteUrl } : {}), socialLinks: resolveHomepageSocialLinks(cfg), pwa: true, // homepage.json's opt-out, so the hub's modal follows the same switch. ...(cfg.transcriptDownloads === false ? { transcriptDownloads: false } : {}), }); } export function currentSite(): Site { if (process.env.INSTANCE_MODE === "hub") return hubSite(); const paths = getPaths(); const explicit = process.env.SITE_ID; if (explicit) return getSite(explicit, paths); const fallback = defaultSiteId(paths); if (fallback) return getSite(fallback, paths); const first = listSiteIds(paths)[0]; if (first) return getSite(first, paths); return parseSite("default", {}); }