Admin-teksten en merklogo: Weergavenaam, Wachtwoord wijzigen, Eerste account aanmaken, logo per thema
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { getBrand, themeLogo } from '@/lib/brand';
|
||||
|
||||
describe('themeLogo', () => {
|
||||
it('points at the emitted logo files under the app base path', () => {
|
||||
expect(themeLogo(true, '/admin/')).toEqual({
|
||||
onLight: '/admin/brand-logo-on-light.png',
|
||||
onDark: '/admin/brand-logo-on-dark.png',
|
||||
});
|
||||
});
|
||||
|
||||
it('tolerates a base without trailing slash and the dev root', () => {
|
||||
expect(themeLogo(true, '/admin')?.onLight).toBe('/admin/brand-logo-on-light.png');
|
||||
expect(themeLogo(true, '/')?.onDark).toBe('/brand-logo-on-dark.png');
|
||||
});
|
||||
|
||||
it('has no logo when the theme ships none', () => {
|
||||
expect(themeLogo(false)).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('getBrand', () => {
|
||||
it('has no logo without a theme (the default admin is unchanged)', () => {
|
||||
expect(getBrand().logo).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* 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) };
|
||||
}
|
||||
Reference in New Issue
Block a user