You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.1 KiB
64 lines
2.1 KiB
9 months ago
|
- let disqusjsPageTitle = page.title.replace(/'/ig,"\\'")
|
||
|
- const { shortname:dqShortname, apikey:dqApikey, option:dqOption } = theme.disqusjs
|
||
|
|
||
|
script.
|
||
|
(() => {
|
||
|
const initDisqusjs = () => {
|
||
|
window.disqusjs = null
|
||
|
disqusjs = new DisqusJS(Object.assign({
|
||
|
shortname: '!{dqShortname}',
|
||
|
identifier: '!{ url_for(page.path) }',
|
||
|
url: '!{ page.permalink }',
|
||
|
title: '!{ disqusjsPageTitle }',
|
||
|
apikey: '!{dqApikey}',
|
||
|
},!{JSON.stringify(dqOption)}))
|
||
|
|
||
|
disqusjs.render(document.getElementById('disqusjs-wrap'))
|
||
|
}
|
||
|
|
||
|
const themeChange = () => {
|
||
|
const ele = document.getElementById('disqus_thread')
|
||
|
if(!ele) return
|
||
|
disqusjs.destroy()
|
||
|
initDisqusjs()
|
||
|
}
|
||
|
|
||
|
btf.addGlobalFn('themeChange', themeChange, 'disqusjs')
|
||
|
|
||
|
const loadDisqusjs = async() => {
|
||
|
if (window.disqusJsLoad) initDisqusjs()
|
||
|
else {
|
||
|
await getCSS('!{url_for(theme.asset.disqusjs_css)}')
|
||
|
await getScript('!{url_for(theme.asset.disqusjs)}')
|
||
|
initDisqusjs()
|
||
|
window.disqusJsLoad = true
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const getCount = async() => {
|
||
|
try {
|
||
|
const eleGroup = document.querySelector('#post-meta .disqusjs-comment-count')
|
||
|
if (!eleGroup) return
|
||
|
const cleanedLinks = eleGroup.href.replace(/#post-comment$/, '')
|
||
|
|
||
|
const res = await fetch(`https://disqus.com/api/3.0/threads/set.json?forum=!{dqShortname}&api_key=!{dqApikey}&thread:link=${cleanedLinks}`,{
|
||
|
method: 'GET'
|
||
|
})
|
||
|
const result = await res.json()
|
||
|
const count = result.response.length ? result.response[0].posts : 0
|
||
|
eleGroup.textContent = count
|
||
|
} catch (err) {
|
||
|
console.error(err)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if ('!{theme.comments.use[0]}' === 'Disqusjs' || !!{theme.comments.lazyload}) {
|
||
|
if (!{theme.comments.lazyload}) btf.loadComment(document.getElementById('disqusjs-wrap'), loadDisqusjs)
|
||
|
else {
|
||
|
loadDisqusjs()
|
||
|
!{ theme.comments.count ? 'GLOBAL_CONFIG_SITE.isPost && getCount()' : '' }
|
||
|
}
|
||
|
} else {
|
||
|
window.loadOtherComment = loadDisqusjs
|
||
|
}
|
||
|
})()
|