- 彻底修复favicon未替换问题:改进Metadata配置,添加客户端FaviconUpdater组件 - 添加缓存破坏参数,确保浏览器正确加载新的favicon - 尺寸调整完成后添加下载按钮 - 保持尺寸编辑状态下左右图片虚线框相同尺寸(714x570px) - 优化工具栏布局,宽高设置移动到选择比例工具栏后面
48 lines
1.5 KiB
TypeScript
48 lines
1.5 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect } from "react";
|
|
|
|
export function FaviconUpdater() {
|
|
useEffect(() => {
|
|
// 从 API 获取最新的 favicon 设置
|
|
fetch("/api/site-settings")
|
|
.then((res) => res.json())
|
|
.then((settings) => {
|
|
if (settings.favicon) {
|
|
const faviconUrl = settings.favicon;
|
|
const timestamp = Date.now();
|
|
const urlWithCache = `${faviconUrl}${faviconUrl.includes("?") ? "&" : "?"}v=${timestamp}`;
|
|
|
|
// 移除所有旧的 favicon link 标签
|
|
const oldLinks = document.querySelectorAll('link[rel*="icon"]');
|
|
oldLinks.forEach((link) => link.remove());
|
|
|
|
// 添加新的 favicon link 标签
|
|
const link = document.createElement("link");
|
|
link.rel = "icon";
|
|
link.type = "image/x-icon";
|
|
link.href = urlWithCache;
|
|
document.head.appendChild(link);
|
|
|
|
// 添加 Apple touch icon
|
|
const appleLink = document.createElement("link");
|
|
appleLink.rel = "apple-touch-icon";
|
|
appleLink.href = urlWithCache;
|
|
document.head.appendChild(appleLink);
|
|
|
|
// 添加 shortcut icon
|
|
const shortcutLink = document.createElement("link");
|
|
shortcutLink.rel = "shortcut icon";
|
|
shortcutLink.href = urlWithCache;
|
|
document.head.appendChild(shortcutLink);
|
|
}
|
|
})
|
|
.catch((error) => {
|
|
console.error("[Favicon] Error updating favicon:", error);
|
|
});
|
|
}, []);
|
|
|
|
return null;
|
|
}
|
|
|