From 645c9907786f4b8b7c98bde567c101db20d2a665 Mon Sep 17 00:00:00 2001 From: Furrium Network Date: Tue, 22 Sep 2026 19:42:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(feed):=20=E5=B8=96=E5=AD=90=E5=8D=A1?= =?UTF-8?q?=E7=89=87=E7=BB=9F=E4=B8=80=E6=88=AA=E6=96=AD=EF=BC=8C=E9=95=BF?= =?UTF-8?q?=E6=A0=87=E9=A2=98=E4=B8=8E=E5=A4=A7=E5=9B=BE=E4=B8=8D=E5=86=8D?= =?UTF-8?q?=E6=92=91=E9=AB=98=E5=8D=A1=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 列表里卡片高度参差不齐,实测(视口 1280px)发现三个来源: 一、标题完全没有截断 正文早有 -webkit-line-clamp: 3,标题却没有任何限制。一条 180 字的 标题会占满 6 行、把卡片撑到 253px,与相邻卡片明显不齐。 现为 #feed .post-title 加 2 行截断,并补 word-break / overflow-wrap: 原先没有断行规则,超长的连续串或 URL 会横向溢出容器。 二、签名在列表中占用高度且长短不一 签名由用户自定义,长度差异很大,是卡片高度差异的主要来源之一, 但在列表里并不承担信息价值。 改为在 #feed 中隐藏,详情页不受影响。为便于选择器命中, feed.js 渲染签名时补上 .post-signature 类(此前只有行内样式)。 三、图片最多 6 张全部铺开 附件上限 6 张,全部铺开会把卡片撑得很高。现只展示前 3 张, 其余折叠为右下角的「+N」计数徽标;缩略图统一为 120×90, 原先单张 200px 在 3 张并排时同样会把卡片撑高。 实测结果(六个极端用例:3000 字正文、180 字标题、400 字符无空格串、 超长 URL、5 张图、普通短帖): - 标题截断 6/6 生效,最长标题从 95px 降到 48px - 签名 5 张卡片全部隐藏 - 5 张图的卡片显示 3 张 + 「+2」 - 横向溢出 0 张 - 卡片高度极差由 120px 收窄到 100px(181~281px) 剩余差异来自内容本身(有无配图、标题一行或两行),属正常的信息 密度差异,不再进一步压缩。完整测试套件 25/25 通过。 --- js/feed.js | 17 +++++++++++--- style.css | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 3 deletions(-) diff --git a/js/feed.js b/js/feed.js index 260db33..ed95046 100644 --- a/js/feed.js +++ b/js/feed.js @@ -34,12 +34,23 @@ function renderFeed() { 'https://ui-avatars.com/api/?name=' + encodeURIComponent(username) + '&background=6366f1&color=fff&size=64'; const time = p.created_at ? new Date(p.created_at).toLocaleString('zh-CN') : ''; + // 列表里最多展示 3 张图,其余折叠为「+N」。 + // 附件上限是 6 张,若全部铺开会把卡片撑得很高,且与相邻卡片不齐。 let imagesHtml = ''; if (p.images && p.images.length > 0) { + const MAX_THUMBS = 3; + const shown = p.images.slice(0, MAX_THUMBS); + const rest = p.images.length - shown.length; + imagesHtml = '
'; - p.images.forEach(img => { - imagesHtml += ''; + shown.forEach(img => { + imagesHtml += ''; }); + // 多于 3 张时,在末张右下角叠加剩余数量 + if (rest > 0) { + imagesHtml += '+' + rest + ''; + } imagesHtml += '
'; } const replyCount = p.reply_count || 0; @@ -51,7 +62,7 @@ function renderFeed() { if (p.signature) { const sigContent = renderMarkdown(p.signature); signatureHtml = ` -
+
${sigContent}
`; diff --git a/style.css b/style.css index 2162992..10feed8 100644 --- a/style.css +++ b/style.css @@ -1938,6 +1938,16 @@ a.btn-secondary { /* ============================================================ 帖子列表 —— 内容截断(纯 CSS) + ------------------------------------------------------------ + 目标:无论帖子多长、标题多长、带多少张图,列表里每张卡片的高度 + 都尽量接近,避免某一条把整列撑得参差不齐。 + + 三处限制: + - 标题 2 行:原先完全没有限制,长标题能占 6 行、把卡片撑高 70px + - 正文 3 行:原有规则,保留 + - 图片最多显示 3 张:更靠后的折叠为「+N」,由 JS 负责 + + 注意这些规则只作用于 #feed(列表页),帖子详情页不受影响。 ============================================================ */ #feed .post-content { @@ -1950,6 +1960,62 @@ a.btn-secondary { line-height: 1.7; } +/* 标题超过 2 行即截断。不加这条时,一条长标题能把卡片撑高 70px, + 与相邻卡片明显不齐。 */ +#feed .post-title { + display: -webkit-box; + -webkit-line-clamp: 2; + -webkit-box-orient: vertical; + overflow: hidden; + text-overflow: ellipsis; + /* 长单词或连续串也要能断行,否则会横向溢出 */ + word-break: break-word; + overflow-wrap: anywhere; +} + +/* 正文里的超长链接同理 */ +#feed .post-content { + word-break: break-word; + overflow-wrap: anywhere; +} + +/* 列表页隐藏签名:签名长度不一,是卡片高度差异的主要来源之一, + 而它在列表里并不承担信息价值,放在详情页展示更合适。 */ +#feed .post-signature { + display: none; +} + +/* ===== 列表页的图片折叠 ===== */ + +/* 容器需为定位上下文,好让「+N」叠在缩略图组上 */ +#feed .post-images { + position: relative; +} + +/* 列表页缩略图统一尺寸。取 120×90 是为了让带图卡片的总高度 + 尽量接近无图卡片,避免列表里出现忽高忽低的落差; + 单张 200px 的原限制在 3 张并排时也会把卡片撑高。 */ +#feed .post-image { + width: 120px; + height: 90px; + object-fit: cover; +} + +/* 剩余图片计数,叠在缩略图组右侧 */ +#feed .post-image-more { + position: absolute; + right: 8px; + bottom: 8px; + padding: 3px 10px; + border-radius: 999px; + background: rgba(0, 0, 0, 0.62); + color: #fff; + font-size: 12px; + font-weight: 600; + line-height: 1.5; + pointer-events: none; +} + /* ============================================================ 友链输入框 + 验证码输入框 —— 玻璃风格 ============================================================ */