hexo-theme-butterfly/layout/includes/third-party/card-post-count/twikoo.pug
Jerry Wong 9a86429484 breaking changes: 適配 disqusjs 3.0
fix: 修復首頁文章 valine 評論數只顯示第一篇的 bug
fix: 修復子目錄下,第三方插件本地資源無法加載的 bug closed #908
fix: 評論系統開啟時 busuanzi 的 page_pv 不顯示的 bug closed #902
fix: 修復 pjax 下,使用 mermaid 跳轉會重新加載的 bug
2022-05-19 16:45:30 +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.innerText = res[index].count
})
}).catch(function (err) {
console.log(err)
})
}
if (typeof twikoo === 'object') {
runTwikoo()
} else {
getScript('!{url_for(theme.asset.twikoo)}').then(runTwikoo)
}
}
window.pjax ? getCount() : window.addEventListener('load', getCount)
})()