fix(feed): 帖子卡片统一截断,长标题与大图不再撑高卡片
列表里卡片高度参差不齐,实测(视口 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 通过。
This commit is contained in:
1 parent
1e05b18f0c
commit
645c990778
2 files changed
+80
-3
No files matched your search
+14
-3
@@ -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 = '<div class="post-images">';
|
||||
p.images.forEach(img => {
|
||||
imagesHtml += '<img src="' + escapeHTML(safeURL(img, { image: true })) + '" class="post-image" style="cursor:pointer;" />';
|
||||
shown.forEach(img => {
|
||||
imagesHtml += '<img src="' + escapeHTML(safeURL(img, { image: true })) +
|
||||
'" class="post-image" style="cursor:pointer;" />';
|
||||
});
|
||||
// 多于 3 张时,在末张右下角叠加剩余数量
|
||||
if (rest > 0) {
|
||||
imagesHtml += '<span class="post-image-more">+' + rest + '</span>';
|
||||
}
|
||||
imagesHtml += '</div>';
|
||||
}
|
||||
const replyCount = p.reply_count || 0;
|
||||
@@ -51,7 +62,7 @@ function renderFeed() {
|
||||
if (p.signature) {
|
||||
const sigContent = renderMarkdown(p.signature);
|
||||
signatureHtml = `
|
||||
<div style="margin-top:10px;padding-top:8px;border-top:1px solid var(--border-light);font-size:12px;color:var(--text-secondary);">
|
||||
<div class="post-signature" style="margin-top:10px;padding-top:8px;border-top:1px solid var(--border-light);font-size:12px;color:var(--text-secondary);">
|
||||
${sigContent}
|
||||
</div>
|
||||
`;
|
||||
|
||||
Reference in new issue
Block a user