perf: optimize Valine comment plugin
This commit is contained in:
parent
9c630a6436
commit
8e92c52ce0
|
@ -1,12 +1,6 @@
|
|||
<div class="comments-container">
|
||||
<div id="comment-anchor"></div>
|
||||
<% if (
|
||||
theme.comment.valine.enable === true
|
||||
&& theme.comment.gitalk.enable === true
|
||||
&& theme.comment.twikoo.enable === true
|
||||
) { %>
|
||||
<%- partial('valine') %>
|
||||
<% } else if (theme.comment.valine.enable === true) { %>
|
||||
<% if (theme.comment.valine.enable === true) { %>
|
||||
<%- partial('valine') %>
|
||||
<% } else if (theme.comment.gitalk.enable === true) { %>
|
||||
<%- partial('gitalk') %>
|
||||
|
|
|
@ -20,20 +20,29 @@
|
|||
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 %>';
|
||||
if (author) {
|
||||
author = author.toLocaleLowerCase();
|
||||
}
|
||||
author && (author = author.toLocaleLowerCase());
|
||||
|
||||
for (let vcard of vcards) {
|
||||
const vnick = vcard.querySelector('.vhead .vnick');
|
||||
if (vnick.innerHTML.toLocaleLowerCase() === author) {
|
||||
vcard.classList.add('author');
|
||||
vnick.innerHTML = `${author} <span class="author">${getAuthor(KEEP.hexo_config.language)}</span>`
|
||||
}
|
||||
}
|
||||
clearInterval(getValineDomTimer);
|
||||
|
|
|
@ -29,7 +29,8 @@ hexo.extend.helper.register('export_config', function () {
|
|||
|
||||
let hexo_config = {
|
||||
hostname: url.parse(config.url).hostname || config.url,
|
||||
root: config.root
|
||||
root: config.root,
|
||||
language: config.language
|
||||
};
|
||||
|
||||
if (config.search) {
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
if (hexo-config('comment.valine.enable') && hexo-config('comment.gitalk.enable') && hexo-config('comment.twikoo.enable')) {
|
||||
@require "./valine.styl";
|
||||
|
||||
} else if (hexo-config('comment.valine.enable')) {
|
||||
if (hexo-config('comment.valine.enable')) {
|
||||
@require "./valine.styl";
|
||||
|
||||
} else if (hexo-config('comment.gitalk.enable')) {
|
||||
|
|
|
@ -68,25 +68,19 @@
|
|||
|
||||
.vcard {
|
||||
|
||||
&.author {
|
||||
.vnick {
|
||||
font-weight: bold;
|
||||
|
||||
&::after {
|
||||
font-weight: 500;
|
||||
font-size: 12px;
|
||||
content: '博主';
|
||||
padding: 2px;
|
||||
background: -webkit-linear-gradient(45deg, #e3565e, #ee854b, #f6c258, #90c68a, #5fb3b3, #6699cc, #c594c5);
|
||||
background: linear-gradient(45deg, #e3565e, #ee854b, #f6c258, #90c68a, #5fb3b3, #6699cc, #c594c5);
|
||||
color: #fff;
|
||||
margin-left: 5px;
|
||||
border-radius: 2px;
|
||||
}
|
||||
.vnick {
|
||||
.author {
|
||||
font-weight: 450;
|
||||
font-size: 12px;
|
||||
padding: 2px;
|
||||
background: -webkit-linear-gradient(45deg, #e3565e, #ee854b, #f6c258, #90c68a, #5fb3b3, #6699cc, #c594c5);
|
||||
background: linear-gradient(45deg, #e3565e, #ee854b, #f6c258, #90c68a, #5fb3b3, #6699cc, #c594c5);
|
||||
color: #fff;
|
||||
margin-left: 2px;
|
||||
border-radius: 2px;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.vhead {
|
||||
|
||||
.vnick {
|
||||
|
|
Loading…
Reference in New Issue