diff --git a/js/app.js b/js/app.js
index 3bee4a8..b00a0f2 100644
--- a/js/app.js
+++ b/js/app.js
@@ -1385,8 +1385,9 @@ async function init() {
renderNav();
await loadForumName();
await loadCustomPagesNav();
- renderStats();
- renderLinks();
+ // renderStats / renderLinks 不在此处调用。下面的页面分发中,
+ // switchPage('feed') 已经会调用它们;若在此处也调一次,
+ // /api/stats 会发出两次请求。
const urlParams = new URLSearchParams(window.location.search);
const postParam = urlParams.get('post');
@@ -1415,6 +1416,14 @@ async function init() {
switchPage('feed');
}
+ // 直接通过 URL 打开帖子详情或用户主页时,不会经过 switchPage('feed'),
+ // 侧边栏的统计与友链需要在这里补一次。已在 feed 分支内调用过的情形
+ // 通过 currentPage 判断,避免重复请求。
+ if (currentPage !== 'feed') {
+ renderStats();
+ renderLinks();
+ }
+
// ============================================================
// 绑定所有事件
// ============================================================
diff --git a/js/feed.js b/js/feed.js
index a6b3032..31de11d 100644
--- a/js/feed.js
+++ b/js/feed.js
@@ -24,7 +24,7 @@ function renderFeed() {
// 造成明显的闪动,反而比直接留白更糟。
const isFirstLoad = container.dataset.loaded !== '1';
container.innerHTML = isFirstLoad
- ? Skeleton.postList(4)
+ ? Skeleton.postList(3)
: '
加载中...
';
API.getPosts(currentSort, currentPageNum, PAGE_SIZE).then(result => {
container.dataset.loaded = '1';
@@ -218,14 +218,9 @@ function renderFeed() {
});
}
-function renderStats() {
- API.getStats().then(stats => {
- document.getElementById('statTopics').textContent = stats.topics || 0;
- document.getElementById('statPosts').textContent = stats.posts || 0;
- document.getElementById('statUsers').textContent = stats.users || 0;
- // 在线人数已移除
- }).catch(() => {});
-}
+// 注:renderStats 定义在 app.js 中(同时更新主页与帖子详情页的统计,
+// 且带空值保护)。此处原先有一份同名实现,因 app.js 后加载而被整体
+// 覆盖,属于死代码,已删除以免日后改错地方。
function renderLinks() {
API.getLinks().then(links => {
diff --git a/js/skeleton.js b/js/skeleton.js
index 4d5f476..b8773b1 100644
--- a/js/skeleton.js
+++ b/js/skeleton.js
@@ -27,10 +27,13 @@ const Skeleton = {
},
// 帖子列表
- postList(count = 4) {
+ // 数量不宜过多:骨架卡片是按「理想内容」画的,实际帖子往往更短
+ // (标题一行、正文一两行),画太多会在真实内容出现时造成容器高度
+ // 骤降,页面内容整体上跳。用 3 张作为折中。
+ postList(count = 3) {
let html = '';
for (let i = 0; i < count; i++) {
- // 第一张带缩略图占位,更接近真实列表的参差感
+ // 第二张带缩略图占位,更接近真实列表的参差感
html += this.postCard({ withThumbs: i === 1 });
}
return html;
@@ -111,7 +114,7 @@ window.Skeleton = Skeleton;
function insert() {
const list = document.getElementById('postList');
if (list && !list.dataset.loaded) {
- list.innerHTML = Skeleton.postList(4);
+ list.innerHTML = Skeleton.postList(3);
}
}
if (document.readyState === 'loading') {
diff --git a/style.css b/style.css
index 2e99e80..8d2fd0e 100644
--- a/style.css
+++ b/style.css
@@ -3468,7 +3468,28 @@ select:disabled {
box-shadow: none !important;
}
-/* 搜索框、验证码等内嵌小输入框同样适用,无需单独处理 */
+/* ===== 列表容器高度稳定 =====
+ 骨架屏按「理想内容」绘制,实际帖子往往更短,数据到达时容器高度会
+ 骤降,导致其下方的内容(分页控件、页脚)整体上跳——这就是首屏
+ 「跳一下」的来源。
+
+ 给容器设一个下限,让高度变化被吸收掉大部分。取值约为三张典型
+ 卡片的高度,既不会在帖子很少时留下大片空白,也能覆盖常见情况。 */
+#postList {
+ min-height: 420px;
+}
+
+/* 移动端一屏更窄,内容更少,下限相应调低 */
+@media (max-width: 768px) {
+ #postList {
+ min-height: 320px;
+ }
+}
+
+/* 内容确实为空时不需要撑高 */
+#postList:empty {
+ min-height: 0;
+}
/* ============================================================
💀 骨架屏