更新UI
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
export type Branding = {
|
||||
siteName: string;
|
||||
portalTitle: string;
|
||||
portalSubtitle: string;
|
||||
adminTitle: string;
|
||||
adminSubtitle: string;
|
||||
siteIconUrl: string;
|
||||
logoUrl: string;
|
||||
developerAvatarUrl: string;
|
||||
developerName: string;
|
||||
feedbackEmail: string;
|
||||
};
|
||||
|
||||
export const defaultBranding: Branding = {
|
||||
siteName: "YMhut Box",
|
||||
portalTitle: "YMhut Box 统一服务门户",
|
||||
portalSubtitle: "统一发布、反馈与接口源状态门户",
|
||||
adminTitle: "YMhut 统一管理台",
|
||||
adminSubtitle: "发布、反馈、接口源与系统运维",
|
||||
siteIconUrl: "/assets/favicon.ico",
|
||||
logoUrl: "/assets/favicon.ico",
|
||||
developerAvatarUrl: "/assets/developer-avatar.png",
|
||||
developerName: "YMhut",
|
||||
feedbackEmail: "support@ymhut.cn",
|
||||
};
|
||||
|
||||
function valueOf(source: any, key: keyof Branding) {
|
||||
const value = source?.[key];
|
||||
return typeof value === "string" && value.trim() ? value.trim() : "";
|
||||
}
|
||||
|
||||
export function normalizeBranding(source: any): Branding {
|
||||
const siteName = valueOf(source, "siteName") || defaultBranding.siteName;
|
||||
const siteIconUrl = valueOf(source, "siteIconUrl") || defaultBranding.siteIconUrl;
|
||||
return {
|
||||
siteName,
|
||||
portalTitle: valueOf(source, "portalTitle") || `${siteName} 统一服务门户`,
|
||||
portalSubtitle: valueOf(source, "portalSubtitle") || defaultBranding.portalSubtitle,
|
||||
adminTitle: valueOf(source, "adminTitle") || defaultBranding.adminTitle,
|
||||
adminSubtitle: valueOf(source, "adminSubtitle") || defaultBranding.adminSubtitle,
|
||||
siteIconUrl,
|
||||
logoUrl: valueOf(source, "logoUrl") || siteIconUrl,
|
||||
developerAvatarUrl: valueOf(source, "developerAvatarUrl") || defaultBranding.developerAvatarUrl,
|
||||
developerName: valueOf(source, "developerName") || defaultBranding.developerName,
|
||||
feedbackEmail: valueOf(source, "feedbackEmail") || defaultBranding.feedbackEmail,
|
||||
};
|
||||
}
|
||||
|
||||
export function applyDocumentBranding(branding: Branding, surface: "portal" | "admin" = "admin") {
|
||||
if (typeof document === "undefined") return;
|
||||
document.title = surface === "admin" ? branding.adminTitle : branding.portalTitle;
|
||||
let icon = document.querySelector<HTMLLinkElement>("link[rel~='icon']");
|
||||
if (!icon) {
|
||||
icon = document.createElement("link");
|
||||
icon.rel = "icon";
|
||||
document.head.appendChild(icon);
|
||||
}
|
||||
icon.href = branding.siteIconUrl;
|
||||
}
|
||||
Reference in New Issue
Block a user