This commit is contained in:
make
2026-01-11 15:59:24 +08:00
parent b6a533a9dd
commit ebbf6c1237

View File

@@ -2619,14 +2619,29 @@ class SiteStyle
*/
private static function buildFavicon(array $TpStyle): string
{
$domain = $_SERVER['HTTP_HOST'] ?? 'cli';
$safe = preg_replace('/[^a-z0-9\.\-]/i', '_', $domain);
// ===== 下面开始“只执行一次”的生成逻辑 =====
$seed = (int)($TpStyle['meta']['seed'] ?? crc32($domain));
$bg = (string)($TpStyle['theme']['theme_color'] ?? '#263238');
$fg = '#ffffff';
// favicon透明背景 + 鲜艳前景(与 UI 解耦)
$bg = 'none';
$iconColors = [
'#E53935',
'#D81B60',
'#8E24AA',
'#3949AB',
'#1E88E5',
'#039BE5',
'#00897B',
'#43A047',
'#FDD835',
'#FB8C00',
'#F4511E',
'#6D4C41',
];
$fg = $iconColors[$seed % count($iconColors)];
$strSvgRoute = '/static/favicon/generated/' . $seed . '/';
$strSvgGenDir = root_path() . 'public/' . $strSvgRoute;
@@ -2639,19 +2654,16 @@ class SiteStyle
@mkdir($strSvgGenDir, 0755, true);
}
// 已生成过,直接复用(冻结)
if (is_file($icoFile) && is_file($svgFile)) {
if (is_file($svgFile)) {
return $strTmpSvgDir;
}
$svgBasePath = root_path() . self::$faviconBaseDir;
$bases = glob($svgBasePath . '*.svg');
if (!$bases) {
// 兜底,不影响上线
return '/favicon.ico';
return '/favicon.svg';
}
// 用 dom_prefix + layout 决定母型(稳定、可回放)
$layout = (string)($TpStyle['global']['theme']['layout'] ?? 'A');
$dom = (string)($TpStyle['meta']['dom_prefix'] ?? '');
@@ -2660,13 +2672,11 @@ class SiteStyle
$svg = file_get_contents($baseSvg);
if ($svg === false) {
return '/favicon.ico';
return '/favicon.svg';
}
// 注入主题色
$svg = str_replace(['VAR_BG', 'VAR_FG'], [$bg, $fg], $svg);
// 持久化 svg便于排查、也便于后续升级
@file_put_contents($svgFile, $svg);
// 转 ico16 / 32目前不使用ico
@@ -2684,4 +2694,72 @@ class SiteStyle
return $strTmpSvgDir;
}
// private static function buildFavicon(array $TpStyle): string
// {
// $domain = $_SERVER['HTTP_HOST'] ?? 'cli';
// $safe = preg_replace('/[^a-z0-9\.\-]/i', '_', $domain);
// // ===== 下面开始“只执行一次”的生成逻辑 =====
// $seed = (int)($TpStyle['meta']['seed'] ?? crc32($domain));
// $bg = (string)($TpStyle['theme']['theme_color'] ?? '#263238');
// $fg = '#ffffff';
// $strSvgRoute = '/static/favicon/generated/' . $seed . '/';
// $strSvgGenDir = root_path() . 'public/' . $strSvgRoute;
// $strTmpSvgDir = $strSvgRoute . 'favicon.svg';
// $svgFile = $strSvgGenDir . 'favicon.svg';
// $icoFile = $strSvgGenDir . 'favicon.ico';
// if (!is_dir($strSvgGenDir)) {
// @mkdir($strSvgGenDir, 0755, true);
// }
// // 已生成过,直接复用(冻结)
// if (is_file($icoFile) && is_file($svgFile)) {
// return $strTmpSvgDir;
// }
// $svgBasePath = root_path() . self::$faviconBaseDir;
// $bases = glob($svgBasePath . '*.svg');
// if (!$bases) {
// // 兜底,不影响上线
// return '/favicon.ico';
// }
// // 用 dom_prefix + layout 决定母型(稳定、可回放)
// $layout = (string)($TpStyle['global']['theme']['layout'] ?? 'A');
// $dom = (string)($TpStyle['meta']['dom_prefix'] ?? '');
// $idx = abs(crc32($layout . '|' . $dom . '|' . $seed)) % count($bases);
// $baseSvg = $bases[$idx];
// $svg = file_get_contents($baseSvg);
// if ($svg === false) {
// return '/favicon.ico';
// }
// // 注入主题色
// $svg = str_replace(['VAR_BG', 'VAR_FG'], [$bg, $fg], $svg);
// // 持久化 svg便于排查、也便于后续升级
// @file_put_contents($svgFile, $svg);
// // 转 ico16 / 32目前不使用ico
// // $bin = 'magick';
// // if (!shell_exec('which magick')) {
// // $bin = 'convert';
// // }
// // $cmd = sprintf(
// // '%s %s -background none -define icon:auto-resize=16,32 %s',
// // $bin,
// // escapeshellarg($svgFile),
// // escapeshellarg($icoFile)
// // );
// // @exec($cmd);
// return $strTmpSvgDir;
// }
}