feat: 图标策略升级 + 引擎显隐就地切换 + 前后台一致性;界面美化
按反馈逐条处理: ① 界面美化 - 前台重做:品牌区(logo + 站名 + 副标题)、胶囊式引擎切换、圆角卡片与 悬停浮起、聚焦光晕、合集标签页淡入动画;版心改为 shell 变量 (--pad-x = max(gutter, (100% - wrap)/2)),与顶栏左右边缘严格对齐。 - 后台:表格窄屏可横向滚动、状态胶囊、自定义徽章、图标预览框。 ② 自动更新图标质量差 + 允许自定义图标 - 抓取改为阶梯择优:manifest 512/192 → apple-touch-icon → <link rel=icon> (按 sizes 降序,SVG 视为最高清)→ 第三方聚合服务(favicon.yandex.net 实测 100% 可用;icon.horse 可达时最高 256px)→ 站点自身 /favicon.ico。 - 逐个候选实测像素,达到 120px 即停;候选上限 8 个 + 10s 总预算,避免超时。 - 用 GD 只缩不放,统一存成 128×128 PNG;识别并丢弃第三方服务的 「灰底字母」占位块。 - 新增 sites.icon_custom 列(带幂等迁移):可上传图标或填图标地址; 一旦自定义,「全部更新」只刷新名称、跳过图标。 ③ 后台引擎「可见/不可见」不好用 - 小图标换成内联 SVG(原来用 emoji,跨字体显示成方块)。 - 切换改为 AJAX 原地生效 + 状态胶囊同步,不再点一下就跳页; 所有切换/移动表单都带 p 参数,无 JS 时也能正确回到当前页。 - 修掉一个隐蔽的成因:本站此前完全不发 Cache-Control/Expires/ETag, 浏览器只能自行猜测缓存策略,导致「改完刷新还是旧的」。现在所有动态页 统一发 no-store/no-cache。 ④ deploy/ 与 data/ 误入版本库 - 两目录整目录忽略,部署脚本移出仓库(存 _tooling/),已 git rm --cached。 (历史提交里仍含这些文件,如需彻底抹除需 git filter-repo,待确认。) 附带修复(线上实测驱动) - 服务器侧页面缓存:宝塔「网站加速」Apache(mod_lua) 版是一层基于 memcached 的 30 秒整页缓存,且**读不到 FastCGI 返回的 Cache-Control**,所以 no-store 挡不住它;唯一信号是请求 cookie X_CACHE=1。已在根 .htaccess 用 RequestHeader 在请求侧注入该标记(实测任何访客均 X-Cache: MISS), PHP 侧另发一颗 cookie 作为 Nginx 环境的兜底(BYPASS_PAGE_CACHE 开关)。 - 静态资源改为「长缓存 + 版本号」:asset()/icon_src() 拼 mtime+size, assets/.htaccess 与根 .htaccess 给出 max-age=31536000 immutable。 - 修 absolutize() 未还原 JSON 转义 \/ 导致部分图标 URL 抓不下来的问题。 - 修部署脚本 md5sum 在 Git Bash 下输出 "hash *path" 导致 38 项假「缺失文件」。
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
<?php
|
||||
/**
|
||||
* 简航 SimpleNav —— 前台首页
|
||||
* 顶部:搜索引擎切换 + 搜索框(带联想下拉)
|
||||
* 顶部:品牌 + 搜索引擎切换 + 搜索框(带联想下拉)
|
||||
* 中部:常用 / 工具等网格板块
|
||||
* 下部:合集(标签页形式,点标签平铺该合集全部链接)
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
require_once __DIR__ . '/functions.php';
|
||||
send_no_cache();
|
||||
|
||||
$pdo = db();
|
||||
|
||||
@@ -23,6 +24,8 @@ foreach ($engines as $en) {
|
||||
}
|
||||
if ($default === null) { $default = $engines[0] ?? null; }
|
||||
|
||||
$primary = setting('primary_color', '#2F6BF7');
|
||||
|
||||
function sites_of(int $gid): array
|
||||
{
|
||||
$st = db()->prepare("SELECT * FROM sites WHERE group_id=? AND is_visible=1 ORDER BY sort_order, id");
|
||||
@@ -34,6 +37,25 @@ function site_label(array $s): string
|
||||
{
|
||||
return $s['short_name'] !== '' ? $s['short_name'] : ($s['name'] !== '' ? $s['name'] : domain_of($s['url']));
|
||||
}
|
||||
|
||||
/** 渲染一个网站格(网格板块与合集共用) */
|
||||
function site_tile(array $s): void
|
||||
{
|
||||
$label = site_label($s);
|
||||
$src = icon_src($s['icon']);
|
||||
?>
|
||||
<li class="site">
|
||||
<a href="<?= e($s['url']) ?>" target="_blank" rel="noopener" title="<?= e($s['name'] ?: $label) ?>">
|
||||
<?php if ($src): ?>
|
||||
<img class="icon" src="<?= e($src) ?>" alt="" loading="lazy">
|
||||
<?php else: ?>
|
||||
<span class="ico-letter" style="background:<?= e(letter_color($label)) ?>"><?= e(mb_substr($label, 0, 1)) ?></span>
|
||||
<?php endif; ?>
|
||||
<span class="name"><?= e($label) ?></span>
|
||||
</a>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
@@ -41,21 +63,32 @@ function site_label(array $s): string
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?= e(site_name()) ?> · <?= e(setting('subtitle', '个人网站导航')) ?></title>
|
||||
<meta name="theme-color" content="<?= e(setting('primary_color', '#2F6BF7')) ?>">
|
||||
<link rel="icon" href="<?= e(url('favicon.ico')) ?>" sizes="any">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="<?= e(url('assets/icons/icon-32.png')) ?>">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="<?= e(url('assets/icons/icon-16.png')) ?>">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="<?= e(url('apple-touch-icon.png')) ?>">
|
||||
<link rel="manifest" href="<?= e(url('site.webmanifest')) ?>">
|
||||
<link rel="stylesheet" href="<?= e(url('assets/css/style.css')) ?>">
|
||||
<meta name="description" content="<?= e(site_name()) ?> —— 个人网站导航">
|
||||
<meta name="theme-color" content="<?= e($primary) ?>">
|
||||
<link rel="icon" href="<?= e(asset('favicon.ico')) ?>" sizes="any">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="<?= e(asset('assets/icons/icon-32.png')) ?>">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="<?= e(asset('assets/icons/icon-16.png')) ?>">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="<?= e(asset('apple-touch-icon.png')) ?>">
|
||||
<link rel="manifest" href="<?= e(asset('site.webmanifest')) ?>">
|
||||
<link rel="stylesheet" href="<?= e(asset('assets/css/style.css')) ?>">
|
||||
<?php if ($primary !== '#2F6BF7'): ?>
|
||||
<style>:root { --primary: <?= e($primary) ?>; }</style>
|
||||
<?php endif; ?>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
|
||||
<!-- 顶部品牌区 -->
|
||||
<header class="hero">
|
||||
<img class="logo" src="<?= e(asset('assets/img/logo.svg')) ?>" alt="<?= e(site_name()) ?>">
|
||||
<h1><?= e(site_name()) ?></h1>
|
||||
<p><?= e(setting('subtitle', '个人网站导航')) ?></p>
|
||||
</header>
|
||||
|
||||
<!-- 顶部搜索 -->
|
||||
<div id="search" class="s-search">
|
||||
<div class="search-type" id="engine-tabs">
|
||||
<?php foreach ($engines as $i => $en): ?>
|
||||
<?php foreach ($engines as $en): ?>
|
||||
<label class="s-engine<?= $default && $en['slug'] === $default['slug'] ? ' active' : '' ?>"
|
||||
data-search="<?= e($en['search_url']) ?>"
|
||||
data-param="<?= e($en['param']) ?>"
|
||||
@@ -73,7 +106,12 @@ function site_label(array $s): string
|
||||
<form id="search-form" action="<?= e($default['search_url'] ?? 'https://cn.bing.com/search') ?>" method="get" target="<?= setting('open_blank', '1') === '1' ? '_blank' : '_self' ?>" rel="noopener">
|
||||
<input type="text" id="search-text" name="<?= e($default['param'] ?? 'q') ?>"
|
||||
placeholder="<?= e(($default['name'] ?? '搜索') . '搜索') ?>" autocomplete="off">
|
||||
<button class="submit" type="submit" aria-label="搜索"></button>
|
||||
<button class="submit" type="submit" aria-label="搜索">
|
||||
<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" aria-hidden="true">
|
||||
<circle cx="11" cy="11" r="7"></circle>
|
||||
<path d="M20 20l-3.6-3.6"></path>
|
||||
</svg>
|
||||
</button>
|
||||
<ul id="word"></ul>
|
||||
</form>
|
||||
</div>
|
||||
@@ -82,18 +120,7 @@ function site_label(array $s): string
|
||||
<?php foreach ($gridGroups as $g): $items = sites_of((int)$g['id']); if (!$items) continue; ?>
|
||||
<ul class="mylist">
|
||||
<li class="title"><?= e($g['name']) ?></li>
|
||||
<?php foreach ($items as $s): $label = site_label($s); $src = icon_src($s['icon']); ?>
|
||||
<li class="site">
|
||||
<a href="<?= e($s['url']) ?>" target="_blank" rel="noopener" title="<?= e($s['name'] ?: $label) ?>">
|
||||
<?php if ($src): ?>
|
||||
<img class="icon" src="<?= e($src) ?>" alt="" loading="lazy">
|
||||
<?php else: ?>
|
||||
<span class="ico-letter" style="background:<?= e(letter_color($label)) ?>"><?= e(mb_substr($label, 0, 1)) ?></span>
|
||||
<?php endif; ?>
|
||||
<span class="name"><?= e($label) ?></span>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
<?php foreach ($items as $s) { site_tile($s); } ?>
|
||||
</ul>
|
||||
<?php endforeach; ?>
|
||||
|
||||
@@ -101,26 +128,17 @@ function site_label(array $s): string
|
||||
<?php if ($tabGroups): ?>
|
||||
<div class="collections">
|
||||
<div class="collections-title">合集</div>
|
||||
<div class="tabs" id="coll-tabs">
|
||||
<div class="tabs" id="coll-tabs" role="tablist">
|
||||
<?php foreach ($tabGroups as $i => $g): ?>
|
||||
<button type="button" class="tab<?= $i === 0 ? ' active' : '' ?>" data-target="coll-<?= (int)$g['id'] ?>"><?= e($g['name']) ?></button>
|
||||
<button type="button" class="tab<?= $i === 0 ? ' active' : '' ?>" role="tab"
|
||||
aria-selected="<?= $i === 0 ? 'true' : 'false' ?>"
|
||||
data-target="coll-<?= (int)$g['id'] ?>"><?= e($g['name']) ?></button>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<div class="tab-panels">
|
||||
<?php foreach ($tabGroups as $i => $g): $items = sites_of((int)$g['id']); ?>
|
||||
<ul class="mylist tab-panel<?= $i === 0 ? ' active' : '' ?>" id="coll-<?= (int)$g['id'] ?>">
|
||||
<?php foreach ($items as $s): $label = site_label($s); $src = icon_src($s['icon']); ?>
|
||||
<li class="site">
|
||||
<a href="<?= e($s['url']) ?>" target="_blank" rel="noopener" title="<?= e($s['name'] ?: $label) ?>">
|
||||
<?php if ($src): ?>
|
||||
<img class="icon" src="<?= e($src) ?>" alt="" loading="lazy">
|
||||
<?php else: ?>
|
||||
<span class="ico-letter" style="background:<?= e(letter_color($label)) ?>"><?= e(mb_substr($label, 0, 1)) ?></span>
|
||||
<?php endif; ?>
|
||||
<span class="name"><?= e($label) ?></span>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
<ul class="mylist tab-panel<?= $i === 0 ? ' active' : '' ?>" id="coll-<?= (int)$g['id'] ?>" role="tabpanel">
|
||||
<?php foreach ($items as $s) { site_tile($s); } ?>
|
||||
</ul>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
@@ -135,6 +153,6 @@ function site_label(array $s): string
|
||||
</div>
|
||||
|
||||
<script>window.SIMPLENAV = { suggest: "<?= e(url('suggest.php')) ?>" };</script>
|
||||
<script src="<?= e(url('assets/js/app.js')) ?>"></script>
|
||||
<script src="<?= e(asset('assets/js/app.js')) ?>"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user