hexo-theme-keep/layout/_partial/comment/valine.ejs

84 lines
2.7 KiB
Plaintext
Raw Normal View History

<%
const { enable: pjax_enable } = theme?.pjax
const {
appid,
appkey,
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">
<script <%= pjax_enable === true ? 'data-pjax' : '' %> src="<%= cdn_url %>"></script>
2020-04-01 12:09:06 +08:00
<div id="vcomments"></div>
<script <%= pjax_enable === true ? 'data-pjax' : '' %>>
function loadValine() {
new Valine({
el: '#vcomments',
appId: '<%= appid %>',
appKey: '<%= appkey %>',
meta: ['nick', 'mail', 'link'],
avatar: 'wavatar',
enableQQ: true,
placeholder: '<%= placeholder %>',
lang: '<%= config.language %>'.toLowerCase()
});
2020-10-28 22:25:26 +08:00
function getAuthor(language) {
switch (language) {
case 'en':
return 'Author';
case 'zh-CN':
return '博主';
default:
return 'Master';
}
}
2021-01-15 16:57:20 +08:00
// Add "Author" identify
const getValineDomTimer = setInterval(() => {
const vcards = document.querySelectorAll('#vcomments .vcards .vcard');
if (vcards.length > 0) {
let author = '<%= theme.base_info.author || config.author %>';
2020-10-28 22:25:26 +08:00
if (author) {
for (let vcard of vcards) {
const vnick_dom = vcard.querySelector('.vhead .vnick');
const vnick = vnick_dom.innerHTML;
if (vnick === author) {
vnick_dom.innerHTML = `${vnick} <span class="author">${getAuthor(KEEP.hexo_config.language)}</span>`
}
}
}
clearInterval(getValineDomTimer);
} else {
clearInterval(getValineDomTimer);
}
}, 2000);
}
if ('<%= pjax_enable %>' === 'true') {
const loadValineTimeout = setTimeout(() => {
loadValine();
clearTimeout(loadValineTimeout);
}, 1000);
} else {
window.addEventListener('DOMContentLoaded', loadValine);
}
2020-04-01 12:09:06 +08:00
</script>
</div>
<% } %>