perf: optimize Valine comment plugin
This commit is contained in:
parent
9c630a6436
commit
8e92c52ce0
|
@ -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') %>
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
|
@ -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')) {
|
||||||
|
|
|
@ -68,24 +68,18 @@
|
||||||
|
|
||||||
.vcard {
|
.vcard {
|
||||||
|
|
||||||
&.author {
|
|
||||||
.vnick {
|
.vnick {
|
||||||
font-weight: bold;
|
.author {
|
||||||
|
font-weight: 450;
|
||||||
&::after {
|
|
||||||
font-weight: 500;
|
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
content: '博主';
|
|
||||||
padding: 2px;
|
padding: 2px;
|
||||||
background: -webkit-linear-gradient(45deg, #e3565e, #ee854b, #f6c258, #90c68a, #5fb3b3, #6699cc, #c594c5);
|
background: -webkit-linear-gradient(45deg, #e3565e, #ee854b, #f6c258, #90c68a, #5fb3b3, #6699cc, #c594c5);
|
||||||
background: linear-gradient(45deg, #e3565e, #ee854b, #f6c258, #90c68a, #5fb3b3, #6699cc, #c594c5);
|
background: linear-gradient(45deg, #e3565e, #ee854b, #f6c258, #90c68a, #5fb3b3, #6699cc, #c594c5);
|
||||||
color: #fff;
|
color: #fff;
|
||||||
margin-left: 5px;
|
margin-left: 2px;
|
||||||
border-radius: 2px;
|
border-radius: 2px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.vhead {
|
.vhead {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue