From 8e92c52ce063a5e13743829e3feccbdf41fb8142 Mon Sep 17 00:00:00 2001 From: XPoet Date: Fri, 15 Jan 2021 16:57:20 +0800 Subject: [PATCH] perf: optimize Valine comment plugin --- layout/_partial/comment/comment.ejs | 8 +----- layout/_partial/comment/valine.ejs | 17 +++++++++--- scripts/helpers/export-config.js | 3 ++- .../css/layout/_partial/comment/comment.styl | 5 +--- .../css/layout/_partial/comment/valine.styl | 26 +++++++------------ 5 files changed, 27 insertions(+), 32 deletions(-) diff --git a/layout/_partial/comment/comment.ejs b/layout/_partial/comment/comment.ejs index 3ca73a2..eb8a06c 100644 --- a/layout/_partial/comment/comment.ejs +++ b/layout/_partial/comment/comment.ejs @@ -1,12 +1,6 @@
- <% 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') %> diff --git a/layout/_partial/comment/valine.ejs b/layout/_partial/comment/valine.ejs index 2c9751d..1bfe114 100755 --- a/layout/_partial/comment/valine.ejs +++ b/layout/_partial/comment/valine.ejs @@ -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} ${getAuthor(KEEP.hexo_config.language)}` } } clearInterval(getValineDomTimer); diff --git a/scripts/helpers/export-config.js b/scripts/helpers/export-config.js index 95eb017..c014176 100644 --- a/scripts/helpers/export-config.js +++ b/scripts/helpers/export-config.js @@ -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) { diff --git a/source/css/layout/_partial/comment/comment.styl b/source/css/layout/_partial/comment/comment.styl index 506ec75..4452c90 100644 --- a/source/css/layout/_partial/comment/comment.styl +++ b/source/css/layout/_partial/comment/comment.styl @@ -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')) { diff --git a/source/css/layout/_partial/comment/valine.styl b/source/css/layout/_partial/comment/valine.styl index 60cfd3f..4de67d8 100644 --- a/source/css/layout/_partial/comment/valine.styl +++ b/source/css/layout/_partial/comment/valine.styl @@ -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 {