/* ═══════════════════════════════════════════════════════════════ MEDIA PATHS Every image field in the API is a filename or a path, and where a bare filename lives is decided here, in one file. One rule: record images are uploads. A value from the media library is already '/uploads/'; a bare filename is a file copied into the uploads directory by hand (fall-retreat-logo.svg was), so it resolves to /uploads/ too. That covers logos, photos, backgrounds, hero slides, block images: everything an editor picks. The site's own chosen assets (the NGU logos in the nav, footer and admin) are the exception: they're bundled from src/assets/logos and imported where they're used, not resolved here. A value that already looks like a path or a URL is returned untouched, so a hand-written entry can point anywhere. server/src/pageMeta.js resolves images for link previews by the same rule; keep the two in step. ═══════════════════════════════════════════════════════════════ */ const ABSOLUTE = /^(https?:|\/|data:)/ /* An uploaded file ('/uploads/…'), a path anywhere on the site, or a full URL: something to use as it is rather than resolve. */ export const isAbsoluteMedia = (file?: string | null) => Boolean(file && ABSOLUTE.test(file)) function inDir(dir: string) { return (file?: string | null): string | null => { if (!file) return null if (ABSOLUTE.test(file)) return file return `${dir}/${file}` } } export const UPLOADS = '/uploads' const inUploads = inDir(UPLOADS) /* One helper per field, all the same rule, so a caller says what the image is and a future exception is one line here. */ export const personPhoto = inUploads export const eventLogo = inUploads export const eventBackground = inUploads export const orgLogo = inUploads export const teamLogo = inUploads export const awardLogo = inUploads /* front_page_slides.media, the hero's photos. */ export const heroPhoto = inUploads /* front_page.video_url when it names a file rather than a link. Videos can't be uploaded through the media library, so a file is one copied into the uploads directory by hand. */ export const heroVideo = inUploads /* content_blocks.media and content_block_items.media. */ export const blockMedia = inUploads /* featured_cards.image. */ export const featuredImage = inUploads /* blog_posts.cover_image and guest_photo. */ export const blogImage = inUploads /* ── By record kind ──────────────────────────────────────────── The timeline sends `logo: { file, kind }` rather than a path, because v_timeline COALESCEs across five tables and only the ref_kind says which one the filename came from. Featured cards send the same shape. Every kind resolves to the uploads directory today; the map is what lets one kind differ later. ───────────────────────────────────────────────────────────── */ const BY_KIND: Record string | null> = { event: eventLogo, organization: orgLogo, team: teamLogo, award: awardLogo, person: personPhoto, // Featured cards (loadFeaturedCards in shape.js) add two of their own. 'event-background': eventBackground, featured: featuredImage, } export function logoForKind( kind?: string | null, file?: string | null, ): string | null { if (!file) return null // An unrecognised kind still renders: a filename with no home // directory is a bug, but a broken says so louder than a // silently absent one. return (BY_KIND[kind ?? ''] ?? blockMedia)(file) } /* Initials for a photo that is missing or fails to load. Same two-word rule PeopleTiles uses. */ export function initials(name = ''): string { return name .trim() .split(/\s+/) .slice(0, 2) .map((word) => word[0] || '') .join('') .toUpperCase() }