fixed 评论bug
This commit is contained in:
1 parent
603e47136a
commit
073db7de79
2 files changed
+26
-11
No files matched your search
@@ -1,6 +1,8 @@
|
|||||||
---
|
---
|
||||||
|
layout: post
|
||||||
title: 给Hugo博客添加瀑布流相册功能
|
title: 给Hugo博客添加瀑布流相册功能
|
||||||
date: 2026-01-30T13:00:00+08:00
|
date: 2026-01-30T13:00:00+08:00
|
||||||
|
updated: 2026-01-30T13:00:00+08:00
|
||||||
draft: false
|
draft: false
|
||||||
author: 小赵同学
|
author: 小赵同学
|
||||||
categories:
|
categories:
|
||||||
@@ -11,8 +13,10 @@ tags:
|
|||||||
- CSS
|
- CSS
|
||||||
- 瀑布流
|
- 瀑布流
|
||||||
- 相册
|
- 相册
|
||||||
|
gemini_comment:
|
||||||
|
location:
|
||||||
|
show_theme: 1
|
||||||
top_img: https://picsum.photos/800/400
|
top_img: https://picsum.photos/800/400
|
||||||
allowComment: true
|
|
||||||
---
|
---
|
||||||
|
|
||||||
前两天逛博客,偶然看到了 [immmmm](https://immmmm.com/album/) 大佬的相册页面,觉得那种瀑布流的布局方式展示照片很有感觉,错落有致。
|
前两天逛博客,偶然看到了 [immmmm](https://immmmm.com/album/) 大佬的相册页面,觉得那种瀑布流的布局方式展示照片很有感觉,错落有致。
|
||||||
|
|||||||
@@ -7,6 +7,18 @@
|
|||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
let isResolved = false;
|
let isResolved = false;
|
||||||
|
|
||||||
|
// 安全获取评论列表的辅助函数
|
||||||
|
const safeGetComments = () => {
|
||||||
|
if (!window.artalk) return null;
|
||||||
|
if (typeof window.artalk.getComments === 'function') return window.artalk.getComments();
|
||||||
|
if (typeof window.artalk.getCommentList === 'function') return window.artalk.getCommentList();
|
||||||
|
// 尝试访问内部数据 (Artalk v2 hack)
|
||||||
|
if (window.artalk.ctx && window.artalk.ctx.get('list') && typeof window.artalk.ctx.get('list').getComments === 'function') {
|
||||||
|
return window.artalk.ctx.get('list').getComments();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
const tryResolve = (data, source) => {
|
const tryResolve = (data, source) => {
|
||||||
if (isResolved) return;
|
if (isResolved) return;
|
||||||
|
|
||||||
@@ -24,8 +36,9 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 1. 立即检查
|
// 1. 立即检查
|
||||||
if (window.artalk && typeof window.artalk.getComments === 'function') {
|
const immediateData = safeGetComments();
|
||||||
tryResolve(window.artalk.getComments(), 'immediate');
|
if (immediateData) {
|
||||||
|
tryResolve(immediateData, 'immediate');
|
||||||
} else {
|
} else {
|
||||||
console.log('[Barrage] Artalk 实例未就绪 (Immediate)');
|
console.log('[Barrage] Artalk 实例未就绪 (Immediate)');
|
||||||
}
|
}
|
||||||
@@ -36,8 +49,8 @@
|
|||||||
if (window.artalk && typeof window.artalk.on === 'function') {
|
if (window.artalk && typeof window.artalk.on === 'function') {
|
||||||
window.artalk.on('list-loaded', (data) => {
|
window.artalk.on('list-loaded', (data) => {
|
||||||
console.log('[Barrage] list-loaded 事件触发');
|
console.log('[Barrage] list-loaded 事件触发');
|
||||||
// 优先使用事件传递的数据(如果有),否则调用 getComments
|
// 优先使用事件传递的数据(如果有),否则尝试主动获取
|
||||||
const comments = (Array.isArray(data) && data.length > 0) ? data : window.artalk.getComments();
|
const comments = (Array.isArray(data) && data.length > 0) ? data : (safeGetComments() || []);
|
||||||
tryResolve(comments, 'event');
|
tryResolve(comments, 'event');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -50,12 +63,10 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pollCount++;
|
pollCount++;
|
||||||
if (window.artalk && typeof window.artalk.getComments === 'function') {
|
|
||||||
// 仅在有数据时才 resolve,避免轮询到空数据提前结束
|
const pollData = safeGetComments();
|
||||||
const data = window.artalk.getComments();
|
if (pollData && Array.isArray(pollData) && pollData.length > 0) {
|
||||||
if (Array.isArray(data) && data.length > 0) {
|
tryResolve(pollData, `poll-${pollCount}`);
|
||||||
tryResolve(data, `poll-${pollCount}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user