hexo-theme-butterfly/layout/includes/third-party/comments/disqusjs.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

65 lines
1.9 KiB
Plaintext

- let disqusjsPageTitle = page.title.replace(/'/ig,"\\'")
script.
function loadDisqusjs () {
function addDisqusjsCSS () {
const ele = document.createElement('link')
ele.rel = 'stylesheet'
ele.href= '!{url_for(theme.asset.disqusjs_css)}'
document.getElementsByTagName('head')[0].appendChild(ele)
}
function initDisqusjs () {
window.disqusjs = null
disqusjs = new DisqusJS(Object.assign({
shortname: '!{theme.disqusjs.shortname}',
identifier: '!{ url_for(page.path) }',
url: '!{ page.permalink }',
title: '!{ disqusjsPageTitle }',
apikey: '!{theme.disqusjs.apikey}',
},!{JSON.stringify(theme.disqusjs.option)}))
disqusjs.render(document.getElementById('disqusjs'))
}
const themeChange = () => {
const ele = document.getElementById('disqus_thread')
if(!ele) return
disqusjs.destroy()
initDisqusjs()
}
document.getElementById('darkmode').addEventListener('click', themeChange)
if (window.disqusJsLoad) initDisqusjs()
else {
addDisqusjsCSS()
getScript('!{url_for(theme.asset.disqusjs)}').then(initDisqusjs)
window.disqusJsLoad = true
}
}
if ('!{theme.comments.use[0]}' === 'Disqusjs' || !!{theme.comments.lazyload}) {
if (!{theme.comments.lazyload}) btf.loadComment(document.getElementById('disqusjs'), loadDisqusjs)
else loadDisqusjs()
}
else {
function loadOtherComment () {
loadDisqusjs()
}
}
if is_post() && !theme.comments.lazyload && theme.comments.count && theme.comments.use[0] === 'Disqusjs'
script.
if (window.DISQUSWIDGETS === undefined) {
var d = document, s = d.createElement('script');
s.src = 'https://!{theme.disqus.shortname}.disqus.com/count.js';
s.id = 'dsq-count-scr';
(d.head || d.body).appendChild(s);
} else {
DISQUSWIDGETS.getCount({reset: true});
}