Merge pull request #224 from xyhcode/main

修复最新评论切换获取
This commit is contained in:
小孙同学 2023-06-30 17:45:54 +08:00 committed by GitHub
commit 831dad39cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 24 deletions

View File

@ -4,23 +4,21 @@
<div class="card-widget card-recent-post" th:fragment="comments">
<div class="item-headline"><i class="iconfont icon-comment-dots"></i><span>最新评论</span></div>
<div class="aside-list" id="newcomm">
</div>
</div>
<script th:src="@{/assets/libs/twikoo/twikoo.all.min.js}"></script>
<script th:if="${theme.config.comments.twikoo && #strings.equals(theme.config.comments.use, 'Twikoo') && not #strings.isEmpty(theme.config.comments.envId)}">
const pagesize = [[${theme.config.sidebar.newcommentnumber}]];
const defaultpagesize = 5;
const finalpagesize = pagesize <= 0 ? defaultpagesize : pagesize;
twikoo.getRecentComments({
envId: [[${ theme.config.comments.envId }]], // 环境 ID
// region: 'ap-guangzhou', // 环境地域,默认为 ap-shanghai如果您的环境地域不是上海需传此参数
pageSize: finalpagesize, // 获取多少条默认10最大100
includeReply: false // 是否包括最新回复默认false
}).then(function (res) {
let commenthtml = '';
res.forEach((items)=>{
commenthtml += `<div class="aside-list-item">
<script th:src="@{/assets/libs/twikoo/twikoo.all.min.js}"></script>
<script th:if="${theme.config.comments.twikoo && #strings.equals(theme.config.comments.use, 'Twikoo') && not #strings.isEmpty(theme.config.comments.envId)}">
(()=>{
const pagesize = [[${theme.config.sidebar.newcommentnumber}]];
const defaultpagesize = 5;
const finalpagesize = pagesize <= 0 ? defaultpagesize : pagesize;
twikoo.getRecentComments({
envId: [[${ theme.config.comments.envId }]], // 环境 ID
// region: 'ap-guangzhou', // 环境地域,默认为 ap-shanghai如果您的环境地域不是上海需传此参数
pageSize: finalpagesize, // 获取多少条默认10最大100
includeReply: false // 是否包括最新回复默认false
}).then(function (res) {
let commenthtml = '';
res.forEach((items)=>{
commenthtml += `<div class="aside-list-item">
<a class="thumbnail" href="${items.url}">
<img loading="lazy" alt="dasda" src="${items.avatar}">
</a>
@ -34,11 +32,17 @@
</div>
</div>
</div>`
});
document.querySelector('#newcomm').innerHTML = commenthtml;
}).catch(function (err) {
// 发生错误
console.error(err);
});
</script>
});
let necomm = document.querySelector('#newcomm')
necomm.innerHTML = commenthtml;
window.lazyLoadInstance && window.lazyLoadInstance.update()
window.pjax && window.pjax.refresh(necomm)
}).catch(function (err) {
// 发生错误
console.error(err);
});
})();
</script>
</div>
</div>
</html>