2022-10-20 23:08:07 +08:00
|
|
|
<%
|
|
|
|
const { enable: pjax_enable } = theme?.pjax
|
|
|
|
const {
|
|
|
|
appid,
|
|
|
|
appkey,
|
2022-11-24 17:56:19 +08:00
|
|
|
server_urls,
|
2022-10-20 23:08:07 +08:00
|
|
|
placeholder
|
|
|
|
} = theme.comment?.valine
|
|
|
|
let cdn_url = '//cdn.jsdelivr.net/npm/valine@latest/dist/Valine.min.js'
|
|
|
|
const { enable: t_cdn_enable, provider: t_cdn_provider } = theme?.cdn
|
|
|
|
if (t_cdn_enable === true) {
|
|
|
|
switch (t_cdn_provider) {
|
|
|
|
case 'jsdelivr':
|
|
|
|
cdn_url = '//cdn.jsdelivr.net/npm/valine@latest/dist/Valine.min.js'
|
|
|
|
break
|
|
|
|
|
|
|
|
case 'unpkg':
|
|
|
|
cdn_url = '//unpkg.com/valine@latest/dist/Valine.min.js'
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
%>
|
|
|
|
<% if(appid && appkey) { %>
|
2020-04-01 12:09:06 +08:00
|
|
|
<div class="valine-container">
|
2022-10-20 23:08:07 +08:00
|
|
|
<script <%= pjax_enable === true ? 'data-pjax' : '' %> src="<%= cdn_url %>"></script>
|
2020-04-01 12:09:06 +08:00
|
|
|
<div id="vcomments"></div>
|
2022-10-20 23:08:07 +08:00
|
|
|
<script <%= pjax_enable === true ? 'data-pjax' : '' %>>
|
|
|
|
function loadValine() {
|
2022-11-24 17:56:19 +08:00
|
|
|
|
|
|
|
const config = {
|
2022-10-20 23:08:07 +08:00
|
|
|
el: '#vcomments',
|
|
|
|
appId: '<%= appid %>',
|
|
|
|
appKey: '<%= appkey %>',
|
|
|
|
meta: ['nick', 'mail', 'link'],
|
|
|
|
avatar: 'wavatar',
|
|
|
|
enableQQ: true,
|
|
|
|
placeholder: '<%= placeholder %>',
|
|
|
|
lang: '<%= config.language %>'.toLowerCase()
|
2022-11-24 17:56:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ('<%= server_urls %>') {
|
|
|
|
config.serverURLs = '<%= server_urls %>'
|
|
|
|
}
|
|
|
|
|
|
|
|
new Valine(config)
|
2020-10-28 22:25:26 +08:00
|
|
|
|
2022-10-20 23:08:07 +08:00
|
|
|
function getAuthor(language) {
|
|
|
|
switch (language) {
|
|
|
|
case 'en':
|
2022-11-24 17:56:19 +08:00
|
|
|
return 'Author'
|
2022-10-20 23:08:07 +08:00
|
|
|
case 'zh-CN':
|
2022-11-24 17:56:19 +08:00
|
|
|
return '博主'
|
2022-10-20 23:08:07 +08:00
|
|
|
default:
|
2022-11-24 17:56:19 +08:00
|
|
|
return 'Master'
|
2022-10-20 23:08:07 +08:00
|
|
|
}
|
|
|
|
}
|
2021-01-15 16:57:20 +08:00
|
|
|
|
2022-10-20 23:08:07 +08:00
|
|
|
// Add "Author" identify
|
|
|
|
const getValineDomTimer = setInterval(() => {
|
2022-11-24 17:56:19 +08:00
|
|
|
const vcards = document.querySelectorAll('#vcomments .vcards .vcard')
|
2022-10-20 23:08:07 +08:00
|
|
|
if (vcards.length > 0) {
|
2022-11-24 17:56:19 +08:00
|
|
|
let author = '<%= theme.base_info.author || config.author %>'
|
2020-10-28 22:25:26 +08:00
|
|
|
|
2022-10-20 23:08:07 +08:00
|
|
|
if (author) {
|
|
|
|
for (let vcard of vcards) {
|
2022-11-24 17:56:19 +08:00
|
|
|
const vnick_dom = vcard.querySelector('.vhead .vnick')
|
|
|
|
const vnick = vnick_dom.innerHTML
|
2022-10-20 23:08:07 +08:00
|
|
|
if (vnick === author) {
|
|
|
|
vnick_dom.innerHTML = `${vnick} <span class="author">${getAuthor(KEEP.hexo_config.language)}</span>`
|
2020-07-22 17:08:07 +08:00
|
|
|
}
|
2022-10-20 23:08:07 +08:00
|
|
|
}
|
|
|
|
}
|
2022-11-24 17:56:19 +08:00
|
|
|
clearInterval(getValineDomTimer)
|
2022-10-20 23:08:07 +08:00
|
|
|
} else {
|
2022-11-24 17:56:19 +08:00
|
|
|
clearInterval(getValineDomTimer)
|
2022-10-20 23:08:07 +08:00
|
|
|
}
|
2022-11-24 17:56:19 +08:00
|
|
|
}, 2000)
|
2022-10-20 23:08:07 +08:00
|
|
|
}
|
2020-12-30 18:11:46 +08:00
|
|
|
|
2022-10-20 23:08:07 +08:00
|
|
|
if ('<%= pjax_enable %>' === 'true') {
|
|
|
|
const loadValineTimeout = setTimeout(() => {
|
2022-11-24 17:56:19 +08:00
|
|
|
loadValine()
|
|
|
|
clearTimeout(loadValineTimeout)
|
|
|
|
}, 1000)
|
2022-10-20 23:08:07 +08:00
|
|
|
} else {
|
2022-11-24 17:56:19 +08:00
|
|
|
window.addEventListener('DOMContentLoaded', loadValine)
|
2022-10-20 23:08:07 +08:00
|
|
|
}
|
2020-04-01 12:09:06 +08:00
|
|
|
</script>
|
|
|
|
</div>
|
|
|
|
<% } %>
|