feat: add author label settings in _config.yml
This commit is contained in:
parent
7389f4fdc6
commit
1268e6ff59
30
_config.yml
30
_config.yml
|
@ -90,6 +90,25 @@ home_article:
|
||||||
limit: 5 # max number of tags shown in home page article block
|
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
|
# Code copy
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
|
@ -121,17 +140,6 @@ copyright_info:
|
||||||
enable: false
|
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
|
# Website count
|
||||||
# ---------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -37,12 +37,12 @@
|
||||||
temp_min2read_count = 0;
|
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">
|
<span class="article-wordcount article-meta-item">
|
||||||
<i class="fas fa-file-word"></i> <span><%= temp_wordcount_count %> <%- __('wordcount') %></span>
|
<i class="fas fa-file-word"></i> <span><%= temp_wordcount_count %> <%- __('wordcount') %></span>
|
||||||
</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">
|
<span class="article-min2read article-meta-item">
|
||||||
<i class="fas fa-clock"></i> <span><%= temp_min2read_count %> <%- __('min2read') %></span>
|
<i class="fas fa-clock"></i> <span><%= temp_min2read_count %> <%- __('min2read') %></span>
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -13,7 +13,9 @@
|
||||||
<div class="info">
|
<div class="info">
|
||||||
<div class="author">
|
<div class="author">
|
||||||
<span class="name"><%= theme.base_info.author || config.author %></span>
|
<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>
|
||||||
<div class="meta-info">
|
<div class="meta-info">
|
||||||
<%- partial('_partial/article-meta-info', {articleObject: page, index: true}) %>
|
<%- partial('_partial/article-meta-info', {articleObject: page, index: true}) %>
|
||||||
|
|
|
@ -29,8 +29,17 @@ hexo.extend.helper.register('createNewArchivePosts', function (posts) {
|
||||||
return postList;
|
return postList;
|
||||||
});
|
});
|
||||||
|
|
||||||
hexo.extend.helper.register('getLevel', function (postCount) {
|
hexo.extend.helper.register('getAuthorLabel', function (postCount, isAuto, labelList) {
|
||||||
return Math.ceil(postCount / 10);
|
|
||||||
|
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) {
|
hexo.extend.helper.register('getPostUrl', function (rootUrl, path) {
|
||||||
|
|
|
@ -70,15 +70,16 @@ $article-title-font-size = 1.6rem;
|
||||||
color: var(--default-text-color);
|
color: var(--default-text-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
.level {
|
.author-label {
|
||||||
margin-left: 10px;
|
margin-left: 10px;
|
||||||
font-size: 0.8rem;
|
font-size: 0.8rem;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
padding: 0 4px;
|
padding: 0 5px;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
background: var(--selection-color);
|
background: var(--selection-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue