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

66 lines
2.6 KiB
Plaintext
Executable File

<% if(
theme.comment.valine.enable
&& theme.comment.valine.appid
&& theme.comment.valine.appkey
) { %>
<div class="valine-container">
<script <%= theme.pjax.enable === true ? 'data-pjax' : '' %>
src="//cdn.jsdelivr.net/npm/valine@latest/dist/Valine.min.js"></script>
<div id="vcomments"></div>
<script <%= theme.pjax.enable === true ? 'data-pjax' : '' %>>
function loadValine() {
new Valine({
el: '#vcomments',
appId: '<%= theme.comment.valine.appid %>',
appKey: '<%= theme.comment.valine.appkey %>',
meta: ['nick', 'mail', 'link'],
avatar: 'wavatar',
enableQQ: true,
placeholder: '<%= theme.comment.valine.placeholder %>',
lang: '<%= config.language %>'.toLowerCase()
});
function getAuthor(language) {
switch (language) {
case 'en':
return 'Author';
case 'zh-CN':
return '博主';
default:
return 'Master';
}
}
// 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 %>';
author && (author = author.toLocaleLowerCase());
for (let vcard of vcards) {
const vnick = vcard.querySelector('.vhead .vnick');
if (vnick.innerHTML.toLocaleLowerCase() === author) {
vnick.innerHTML = `${author} <span class="author">${getAuthor(KEEP.hexo_config.language)}</span>`
}
}
clearInterval(getValineDomTimer);
} else {
clearInterval(getValineDomTimer);
}
}, 2000);
}
if ('<%= theme.pjax.enable %>') {
const loadValineTimeout = setTimeout(() => {
loadValine();
clearTimeout(loadValineTimeout);
}, 1000);
} else {
window.addEventListener('DOMContentLoaded', loadValine);
}
</script>
</div>
<% } %>