feat(web/m7-363): branding helper + window.__MINSTREL__ consumer
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
declare global {
|
||||
interface Window {
|
||||
__MINSTREL__?: { appName: string; description: string };
|
||||
}
|
||||
}
|
||||
|
||||
const DEFAULT_APP_NAME = 'Minstrel';
|
||||
const DEFAULT_DESCRIPTION =
|
||||
'Self-hosted music server with Subsonic compatibility, smart shuffle, and Lidarr integration.';
|
||||
|
||||
const isRenderedToken = (v: string | undefined): v is string =>
|
||||
typeof v === 'string' && v.length > 0 && !v.includes('{{');
|
||||
|
||||
export const appName = (): string => {
|
||||
if (typeof window === 'undefined') return DEFAULT_APP_NAME;
|
||||
return isRenderedToken(window.__MINSTREL__?.appName)
|
||||
? window.__MINSTREL__!.appName
|
||||
: DEFAULT_APP_NAME;
|
||||
};
|
||||
|
||||
export const description = (): string => {
|
||||
if (typeof window === 'undefined') return DEFAULT_DESCRIPTION;
|
||||
return isRenderedToken(window.__MINSTREL__?.description)
|
||||
? window.__MINSTREL__!.description
|
||||
: DEFAULT_DESCRIPTION;
|
||||
};
|
||||
|
||||
export const pageTitle = (section?: string): string =>
|
||||
section ? `${appName()} · ${section}` : appName();
|
||||
|
||||
// Ensure this file is treated as a module (the global declaration above
|
||||
// otherwise turns it into a global script).
|
||||
export {};
|
||||
Reference in New Issue
Block a user