diff --git a/_config.yml b/_config.yml index 74a2509..cccb4f9 100644 --- a/_config.yml +++ b/_config.yml @@ -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 # --------------------------------------------------------------------------------------- diff --git a/layout/_partial/article-meta-info.ejs b/layout/_partial/article-meta-info.ejs index 128e828..97f8983 100644 --- a/layout/_partial/article-meta-info.ejs +++ b/layout/_partial/article-meta-info.ejs @@ -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){ %>  <%= temp_wordcount_count %> <%- __('wordcount') %> <% } %> - <% 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){ %>  <%= temp_min2read_count %> <%- __('min2read') %> diff --git a/layout/article-content.ejs b/layout/article-content.ejs index a41909a..6ec987c 100644 --- a/layout/article-content.ejs +++ b/layout/article-content.ejs @@ -13,7 +13,9 @@
<%= theme.base_info.author || config.author %> - Lv<%- getLevel(site.posts.length) %> + <% if (theme.hasOwnProperty('post') && theme.post.author_label.enable === true) { %> + <%- getAuthorLabel(site.posts.length, theme.post.author_label.auto, theme.post.author_label.custom_label_list) %> + <% } %>
<%- partial('_partial/article-meta-info', {articleObject: page, index: true}) %> diff --git a/scripts/helpers/helper.js b/scripts/helpers/helper.js index 5a69a7a..9217f6d 100644 --- a/scripts/helpers/helper.js +++ b/scripts/helpers/helper.js @@ -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) { diff --git a/source/css/layout/article-content.styl b/source/css/layout/article-content.styl index feed424..6337bb8 100644 --- a/source/css/layout/article-content.styl +++ b/source/css/layout/article-content.styl @@ -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); } + } }