Skip to content

Commit

Permalink
perf: optimize Valine comment plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
XPoet committed Jan 15, 2021
1 parent 9c630a6 commit 8e92c52
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 32 deletions.
8 changes: 1 addition & 7 deletions layout/_partial/comment/comment.ejs
Original file line number Diff line number Diff line change
@@ -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') %>
Expand Down
17 changes: 13 additions & 4 deletions layout/_partial/comment/valine.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion scripts/helpers/export-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 1 addition & 4 deletions source/css/layout/_partial/comment/comment.styl
Original file line number Diff line number Diff line change
@@ -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')) {
Expand Down
26 changes: 10 additions & 16 deletions source/css/layout/_partial/comment/valine.styl
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8e92c52

Please sign in to comment.