init...
This commit is contained in:
19
themes/anzhiyu/hexo-theme-anzhiyu-main/layout/includes/third-party/card-post-count/artalk.pug
vendored
Normal file
19
themes/anzhiyu/hexo-theme-anzhiyu-main/layout/includes/third-party/card-post-count/artalk.pug
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
- const { server, site } = theme.artalk
|
||||
|
||||
script.
|
||||
(() => {
|
||||
const getArtalkCount = () => {
|
||||
const runWidget = () => {
|
||||
Artalk.loadCountWidget({
|
||||
server: '!{server}',
|
||||
site: '!{site}',
|
||||
countEl: '.artalk-count'
|
||||
})
|
||||
}
|
||||
|
||||
if (typeof Artalk === 'function') runWidget()
|
||||
else getScript('!{theme.asset.artalk_js}').then(runWidget)
|
||||
}
|
||||
|
||||
window.pjax ? getArtalkCount() : window.addEventListener('load', getArtalkCount)
|
||||
})()
|
||||
9
themes/anzhiyu/hexo-theme-anzhiyu-main/layout/includes/third-party/card-post-count/index.pug
vendored
Normal file
9
themes/anzhiyu/hexo-theme-anzhiyu-main/layout/includes/third-party/card-post-count/index.pug
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
case theme.comments.use[0]
|
||||
when 'Twikoo'
|
||||
include ./twikoo.pug
|
||||
when 'Valine'
|
||||
include ./valine.pug
|
||||
when 'Waline'
|
||||
include ./waline.pug
|
||||
when 'Artalk'
|
||||
include ./artalk.pug
|
||||
37
themes/anzhiyu/hexo-theme-anzhiyu-main/layout/includes/third-party/card-post-count/twikoo.pug
vendored
Normal file
37
themes/anzhiyu/hexo-theme-anzhiyu-main/layout/includes/third-party/card-post-count/twikoo.pug
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
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 {
|
||||
getScript('!{url_for(theme.asset.twikoo)}').then(runTwikoo)
|
||||
}
|
||||
}
|
||||
|
||||
window.pjax ? getCount() : window.addEventListener('load', getCount)
|
||||
|
||||
})()
|
||||
20
themes/anzhiyu/hexo-theme-anzhiyu-main/layout/includes/third-party/card-post-count/valine.pug
vendored
Normal file
20
themes/anzhiyu/hexo-theme-anzhiyu-main/layout/includes/third-party/card-post-count/valine.pug
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
script.
|
||||
(() => {
|
||||
function loadValine () {
|
||||
function initValine () {
|
||||
let initData = {
|
||||
el: '#vcomment',
|
||||
appId: '#{theme.valine.appId}',
|
||||
appKey: '#{theme.valine.appKey}',
|
||||
serverURLs: '#{theme.valine.serverURLs}'
|
||||
}
|
||||
|
||||
const valine = new Valine(initData)
|
||||
}
|
||||
|
||||
if (typeof Valine === 'function') initValine()
|
||||
else getScript('!{url_for(theme.asset.valine)}').then(initValine)
|
||||
}
|
||||
|
||||
window.pjax ? loadValine() : window.addEventListener('load', loadValine)
|
||||
})()
|
||||
21
themes/anzhiyu/hexo-theme-anzhiyu-main/layout/includes/third-party/card-post-count/waline.pug
vendored
Normal file
21
themes/anzhiyu/hexo-theme-anzhiyu-main/layout/includes/third-party/card-post-count/waline.pug
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
- const serverURL = theme.waline.serverURL.replace(/\/$/, '')
|
||||
script.
|
||||
(() => {
|
||||
async function loadWaline () {
|
||||
try {
|
||||
const eleGroup = document.querySelectorAll('#recent-posts .waline-comment-count')
|
||||
const keyArray = Array.from(eleGroup).map(i => i.getAttribute('data-path'))
|
||||
|
||||
const res = await fetch(`!{serverURL}/api/comment?type=count&url=${keyArray}`, { method: 'GET' })
|
||||
const result = await res.json()
|
||||
|
||||
result.data.forEach((count, index) => {
|
||||
eleGroup[index].textContent = count
|
||||
})
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
|
||||
window.pjax ? loadWaline() : window.addEventListener('load', loadWaline)
|
||||
})()
|
||||
Reference in New Issue
Block a user