Files
hexo-theme-butterfly/layout/includes/third-party/card-post-count/twikoo.pug
Jerry 9e0dce6c7a feat: 修改 toc 打開效果
feat: 適配 hexo-blog-encrypt
fix: 修復 hexo 新版本下,prismjs 的問題
improvement: 在 pjax 關閉的情況下。減少不必要的全局變量
improvement: 更新依賴版本
improvement: 頁面進入效果優化
improvement: 添加平滑滾動
improvement: 兼容性優化
improvement: 優化 lighthouse 分數
improvement: 優化代碼
2024-04-02 23:44:46 +08:00

37 lines
1.0 KiB
Plaintext

script.
(() => {
const getCommentUrl = () => {
const eleGroup = document.querySelectorAll('#recent-posts .article-title')
let urlArray = []
eleGroup.forEach(i=>{
urlArray.push(i.getAttribute('href'))
})
return urlArray
}
const getCount = () => {
const runTwikoo = () => {
twikoo.getCommentsCount({
envId: '!{theme.twikoo.envId}',
region: '!{theme.twikoo.region}',
urls: getCommentUrl(),
includeReply: false
}).then(function (res) {
document.querySelectorAll('#recent-posts .twikoo-count').forEach((item,index) => {
item.textContent = res[index].count
})
}).catch(function (err) {
console.log(err)
})
}
if (typeof twikoo === 'object') {
runTwikoo()
} else {
btf.getScript('!{url_for(theme.asset.twikoo)}').then(runTwikoo)
}
}
window.pjax ? getCount() : window.addEventListener('load', getCount)
})()