hexo yelee主题添加字数统计和阅读时长

1.安装 hexo-wordcount

在博客目录下打开Git Bash Here 输入命令

npm i –save hexo-wordcount

2.文件配置

theme\yelee\layout\_partial\post下创建word.ejs文件:

<div style="margin-top:10px 0;margin-bottom:30px;">
    <span class="post-time">
      <span class="post-meta-item-icon">
        <i class="fa fa-keyboard-o"></i>
        <span class="post-meta-item-text">  字数统计: </span>
        <span class="post-count"><%= wordcount(post.content) %>字</span>
      </span>
    </span>

    <span class="post-time">
      &nbsp; | &nbsp;
      <span class="post-meta-item-icon">
        <i class="fa fa-hourglass-half"></i>
        <span class="post-meta-item-text">  阅读时长: </span>
        <span class="post-count"><%= min2read(post.content) %>分</span>
      </span>
    </span>
</div>

如果跟标签有重叠的话,修改第一行margin-bottom:后面的数值。

然后在 themes/yelee/layout/_partial/article.ejs中添加

<div class="article-inner">
    <% if (theme.fancybox){ %>
      <input type="hidden" class="isFancy" />
    <% } %>
    <% if (post.link || post.title){ %>
      <header class="article-header">
        <%- partial('post/title', {class_name: 'article-title'}) %>
        <!-- 开始添加字数统计-->
        <% if(theme.word_count && !post.no_word_count){%>
          <%- partial('post/word') %>
          <% } %>
         <!-- 添加完成 -->
      </header>

注意是放在上述代码段中间

3.开启功能

在yelee主题的_config.yml中添加下面代码

# 是否开启字数统计
#不需要使用,直接设置值为false,或注释掉
word_count: True

主要是根据这篇博客在yelee上进行配置。
代码在其基础上稍作了适配修改。

效果预览:我的博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值