Files
slp-modular-cms/frontend/src/lib/brand.ts
T

34 lines
1.3 KiB
TypeScript

/**
* The site's brand as the admin shows it: one place, so where it comes from can change later
* without touching the components that draw it.
*
* Today the logo is a build-time theme asset (themes/<VITE_THEME>/logo-on-*.png, emitted by
* vite.config.ts). When brand settings become editable (site settings), only getBrand() changes:
* it would return the stored logo URLs instead, and BrandLogo keeps working as is.
*/
export interface BrandLogo {
/** For light backgrounds (dark ink). */
onLight: string;
/** For dark backgrounds (light ink). */
onDark: string;
}
export interface Brand {
/** Absent when the site has no logo: callers fall back to the application name. */
logo: BrandLogo | null;
}
declare const __THEME_HAS_LOGO__: boolean | undefined;
export function themeLogo(hasLogo: boolean, base: string = import.meta.env.BASE_URL): BrandLogo | null {
if (!hasLogo) return null;
const prefix = base.endsWith('/') ? base : `${base}/`;
return { onLight: `${prefix}brand-logo-on-light.png`, onDark: `${prefix}brand-logo-on-dark.png` };
}
export function getBrand(): Brand {
// Defined by vite.config.ts; absent where that config does not run.
const hasLogo = typeof __THEME_HAS_LOGO__ !== 'undefined' && __THEME_HAS_LOGO__;
return { logo: themeLogo(hasLogo) };
}