feat: add author label settings in _config.yml

This commit is contained in:
XPoet 2021-01-28 16:23:47 +08:00
parent 7389f4fdc6
commit 1268e6ff59
5 changed files with 38 additions and 18 deletions

View File

@ -90,6 +90,25 @@ home_article:
limit: 5 # max number of tags shown in home page article block
# ---------------------------------------------------------------------------------------
# Post page Settings
# ---------------------------------------------------------------------------------------
post:
# Post word count
# Dependencies: hexo-wordcount (npm install hexo-wordcount)
# See: https://github.com/willin/hexo-wordcount
word_count:
enable: false
wordcount: false # word count, one article
min2read: false # time to read, one article
author_label:
enable: true
auto: true # if true, show Lv1, Lv2, Lv3... , If false, show custom label
# label array item can be one or more
custom_label_list: [ "Trainee", "Engineer", "Architect", "CTO", "BOSS" ]
# ---------------------------------------------------------------------------------------
# Code copy
# ---------------------------------------------------------------------------------------
@ -121,17 +140,6 @@ copyright_info:
enable: false
# ---------------------------------------------------------------------------------------
# Post word count
# Dependencies: hexo-wordcount
# See: https://github.com/willin/hexo-wordcount
# ---------------------------------------------------------------------------------------
post_wordcount:
enable: false
wordcount: false # word count, one article
min2read: false # time to read, one article
# ---------------------------------------------------------------------------------------
# Website count
# ---------------------------------------------------------------------------------------

View File

@ -37,12 +37,12 @@
temp_min2read_count = 0;
}
%>
<% if(is_post() && theme.post_wordcount.enable && theme.post_wordcount.wordcount && temp_wordcount_count){ %>
<% if(is_post() && theme.hasOwnProperty('post') && theme.post.word_count.enable && theme.post.word_count.wordcount && temp_wordcount_count){ %>
<span class="article-wordcount article-meta-item">
<i class="fas fa-file-word"></i>&nbsp;<span><%= temp_wordcount_count %> <%- __('wordcount') %></span>
</span>
<% } %>
<% if(is_post() && theme.post_wordcount.enable && theme.post_wordcount.min2read && temp_min2read_count){ %>
<% if(is_post() && theme.hasOwnProperty('post') && theme.post.word_count.enable && theme.post.word_count.min2read && temp_min2read_count){ %>
<span class="article-min2read article-meta-item">
<i class="fas fa-clock"></i>&nbsp;<span><%= temp_min2read_count %> <%- __('min2read') %></span>
</span>

View File

@ -13,7 +13,9 @@
<div class="info">
<div class="author">
<span class="name"><%= theme.base_info.author || config.author %></span>
<span class="level">Lv<%- getLevel(site.posts.length) %></span>
<% if (theme.hasOwnProperty('post') && theme.post.author_label.enable === true) { %>
<span class="author-label"><%- getAuthorLabel(site.posts.length, theme.post.author_label.auto, theme.post.author_label.custom_label_list) %></span>
<% } %>
</div>
<div class="meta-info">
<%- partial('_partial/article-meta-info', {articleObject: page, index: true}) %>

View File

@ -29,8 +29,17 @@ hexo.extend.helper.register('createNewArchivePosts', function (posts) {
return postList;
});
hexo.extend.helper.register('getLevel', function (postCount) {
return Math.ceil(postCount / 10);
hexo.extend.helper.register('getAuthorLabel', function (postCount, isAuto, labelList) {
let level = Math.floor(Math.log2(postCount));
level = level < 2 ? 1 : level - 1;
if (isAuto === false && Array.isArray(labelList) && labelList.length > 0) {
return level > labelList.length ? labelList[labelList.length - 1] : labelList[level - 1];
} else {
return `Lv${level}`;
}
});
hexo.extend.helper.register('getPostUrl', function (rootUrl, path) {

View File

@ -70,15 +70,16 @@ $article-title-font-size = 1.6rem;
color: var(--default-text-color);
}
.level {
.author-label {
margin-left: 10px;
font-size: 0.8rem;
font-weight: 500;
padding: 0 4px;
padding: 0 5px;
border-radius: 5px;
color: #fff;
background: var(--selection-color);
}
}
}