feat: 支持配置系统图标
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
export const DEFAULT_APP_ICON_URL = '/app-icon.svg';
|
||||
|
||||
export function resolveAppIcon(url?: string | null): string {
|
||||
const value = String(url || '').trim();
|
||||
return value || DEFAULT_APP_ICON_URL;
|
||||
}
|
||||
|
||||
export function setFavicon(url?: string | null): void {
|
||||
const href = resolveAppIcon(url);
|
||||
const selectors = ['link[rel="icon"]', 'link[rel="shortcut icon"]'];
|
||||
let link = document.head.querySelector<HTMLLinkElement>(selectors.join(','));
|
||||
if (!link) {
|
||||
link = document.createElement('link');
|
||||
link.rel = 'icon';
|
||||
document.head.appendChild(link);
|
||||
}
|
||||
link.type = href.endsWith('.svg') ? 'image/svg+xml' : '';
|
||||
link.href = href;
|
||||
}
|
||||
Reference in New Issue
Block a user