Hexo个人博客之yilia主题阅读量和文章字数统计

前言:关于yilia的配置修改我已近写在上一篇文章中了,本文章主要讲的是文章阅读量和文章字数统计

1. 添加不蒜子统计文章访问量

  • 打开D:\blog_hexo\themes\yilia\layout\_partial\footer.ejs,用以下代码替换
<footer id="footer">
 <div class="outer">
   <div id="footer-info">
     <div class="footer-left">
       &copy; <%= date(new Date(), 'YYYY') %> <%= config.author || config.title %>
     </div>
     <div class="footer-right">
         <a href="http://hexo.io/" target="_blank">Hexo</a>  Theme <a href="https://github.com/litten/hexo-theme-yilia" target="_blank">Yilia</a> by Litten
     </div>
   </div>
   <div calss="count-span">
     <span id="busuanzi_container_site_pv">
         总访问量: <span id="busuanzi_value_site_pv"></span>
   </div>
 </div>
</footer>


<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
  • 打开D:\blog_hexo\themes\yilia\layout\_partial\article.ejs,在<header class="article-header"> 里加如下代码:
    <!-- 添加代码 -->
    <% if ( !index ){ %>
        <span class="archive-article-date">
            阅读量 <span id="busuanzi_value_page_pv"></span>
        </span>
    <% } %>

在这里插入图片描述
更改之后的效果

在这里插入图片描述
在这里插入图片描述

2. 添加统计

2.1 安装字数统计插件
npm i –save hexo-wordcount
2.2 在D:\blog_hexo\themes\yilia\layout\_partial\post下创建word.ejs文件,并写入内容
<div style="margin-top:10px;">
    <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>
2.3 在D:\blog_hexo\themes\yilia\layout\_partial\article.ejs中添加
        <!-- 需要添加的位置 -->
        <!-- 开始添加字数统计-->
        <% if(theme.word_count && !post.no_word_count){%>
          <%- partial('post/word') %>
          <% } %>
        <!-- 添加完成 -->

在这里插入图片描述

重新运行后的效果

在这里插入图片描述

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值