perf: optimize Valine comment plugin

This commit is contained in:
XPoet 2021-01-15 16:57:20 +08:00
parent 9c630a6436
commit 8e92c52ce0
5 changed files with 27 additions and 32 deletions

View File

@ -1,12 +1,6 @@
<div class="comments-container"> <div class="comments-container">
<div id="comment-anchor"></div> <div id="comment-anchor"></div>
<% if ( <% if (theme.comment.valine.enable === true) { %>
theme.comment.valine.enable === true
&& theme.comment.gitalk.enable === true
&& theme.comment.twikoo.enable === true
) { %>
<%- partial('valine') %>
<% } else if (theme.comment.valine.enable === true) { %>
<%- partial('valine') %> <%- partial('valine') %>
<% } else if (theme.comment.gitalk.enable === true) { %> <% } else if (theme.comment.gitalk.enable === true) { %>
<%- partial('gitalk') %> <%- partial('gitalk') %>

View File

@ -20,20 +20,29 @@
lang: '<%= config.language %>'.toLowerCase() lang: '<%= config.language %>'.toLowerCase()
}); });
function getAuthor(language) {
switch (language) {
case 'en':
return 'Author';
case 'zh-CN':
return '博主';
default:
return 'Master';
}
}
// Add "Author" identify // Add "Author" identify
const getValineDomTimer = setInterval(() => { const getValineDomTimer = setInterval(() => {
const vcards = document.querySelectorAll('#vcomments .vcards .vcard'); const vcards = document.querySelectorAll('#vcomments .vcards .vcard');
if (vcards.length > 0) { if (vcards.length > 0) {
let author = '<%= theme.base_info.author || config.author %>'; let author = '<%= theme.base_info.author || config.author %>';
if (author) { author && (author = author.toLocaleLowerCase());
author = author.toLocaleLowerCase();
}
for (let vcard of vcards) { for (let vcard of vcards) {
const vnick = vcard.querySelector('.vhead .vnick'); const vnick = vcard.querySelector('.vhead .vnick');
if (vnick.innerHTML.toLocaleLowerCase() === author) { if (vnick.innerHTML.toLocaleLowerCase() === author) {
vcard.classList.add('author'); vnick.innerHTML = `${author} <span class="author">${getAuthor(KEEP.hexo_config.language)}</span>`
} }
} }
clearInterval(getValineDomTimer); clearInterval(getValineDomTimer);

View File

@ -29,7 +29,8 @@ hexo.extend.helper.register('export_config', function () {
let hexo_config = { let hexo_config = {
hostname: url.parse(config.url).hostname || config.url, hostname: url.parse(config.url).hostname || config.url,
root: config.root root: config.root,
language: config.language
}; };
if (config.search) { if (config.search) {

View File

@ -1,7 +1,4 @@
if (hexo-config('comment.valine.enable') && hexo-config('comment.gitalk.enable') && hexo-config('comment.twikoo.enable')) { if (hexo-config('comment.valine.enable')) {
@require "./valine.styl";
} else if (hexo-config('comment.valine.enable')) {
@require "./valine.styl"; @require "./valine.styl";
} else if (hexo-config('comment.gitalk.enable')) { } else if (hexo-config('comment.gitalk.enable')) {

View File

@ -68,25 +68,19 @@
.vcard { .vcard {
&.author { .vnick {
.vnick { .author {
font-weight: bold; font-weight: 450;
font-size: 12px;
&::after { padding: 2px;
font-weight: 500; background: -webkit-linear-gradient(45deg, #e3565e, #ee854b, #f6c258, #90c68a, #5fb3b3, #6699cc, #c594c5);
font-size: 12px; background: linear-gradient(45deg, #e3565e, #ee854b, #f6c258, #90c68a, #5fb3b3, #6699cc, #c594c5);
content: ''; color: #fff;
padding: 2px; margin-left: 2px;
background: -webkit-linear-gradient(45deg, #e3565e, #ee854b, #f6c258, #90c68a, #5fb3b3, #6699cc, #c594c5); border-radius: 2px;
background: linear-gradient(45deg, #e3565e, #ee854b, #f6c258, #90c68a, #5fb3b3, #6699cc, #c594c5);
color: #fff;
margin-left: 5px;
border-radius: 2px;
}
} }
} }
.vhead { .vhead {
.vnick { .vnick {