1、左侧显示总文章数
打开 themes/yilia/layout_partial/left-col.ejs
文件
在:
<nav class="header-menu">
<ul>
<% for (var i in theme.menu){ %>
<li><a href="<%- url_for(theme.menu[i]) %>"><%= i %></a></li>
<%}%>
</ul>
</nav>
后面添加:
<nav>
总文章数 <%=site.posts.length%>
</nav>
2、添加字数统计
首先安装 hexo-wordcount
使用命令安装: npm i --save hexo-wordcount
Node 版本 7.6.0 之前,请安装 2.x 版本 (Node.js v7.6.0 and previous)
npm install hexo-wordcount@2 --save
然后在 themes\yilia\layout\_partial\left-col.ejs
中添加:
总字数 <span class="post-count"><%= totalcount(site, '0,0.0a') %></span>
编辑 themes\yilia\layout_partial\article.ejs
在 header 下面加入:
<div align="center" class="post-count">
字数:<%= wordcount(post.content) %>字 | 预计阅读时长:<%= min2read(post.content) %>分钟</div>
即可显示单篇字数和预计阅读时长。
3、增加流量统计
使用不蒜子 进行流量统计:
在 themes/yilia/layout/_partial/footer.ejs
中加入以下代码:
<!-- 根据个人喜好在相应位置添加以下代码 -->
<div calss="count-span">
<span id="busuanzi_container_site_pv">
总访问量: <span id="busuanzi_value_site_pv"></span>|
</span>
<span id="busuanzi_container_site_uv">
总访客: <span id="busuanzi_value_site_uv"></span>
</span>
</div>
<!-- 根据个人喜好在相应位置添加以上代码 -->
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
文章访问量统计:
在 /themes/yilia/layout/_partial/article.ejs
中,在header后面加上:
<!-- 文章访问量 -->
<% if ( !index ){ %>
<span class="archive-article-date">
阅读量: <span id="busuanzi_value_page_pv"></span>
</span>
<% } %>
然后重新部署发布博客即可。
4、修改页面右下角的 Hexo Theme Yilia by Litten
在 ****blog/themes/yilia/layout/_partial
目录下找到 footer.ejs
文件 修改里面的:
<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>
5、增加文章置顶功能
修改Hexo文件夹下的node_modules/hexo-generator-index/lib/generator.js
,在生成文章之前进行文章top值排序。
(在 var定义的值之后) 需要添加的代码:
posts.data = posts.data.sort(function(a, b) {
if(a.top && b.top) { // 两篇文章top都有定义
if(a.top == b.top) return b.date - a.date; // 若top值一样则按照文章日期降序排
else return b.top - a.top; // 否则按照top值降序排
}
else if(a.top && !b.top) { // 以下是只有一篇文章top有定义,那么将有top的排在前面(这里用异或操作居然不行233)
return -1;
}
else if(!a.top && b.top) {
return 1;
}
else return b.date - a.date; // 都没定义按照文章日期降序排
});
6、截断文章
在文章需要截断的地方添加 <!-- more -->
即可将文章截成两段,前面的在标签内显示,后面的只有点开全文的时候才能显示。
去掉 标签界面中 more 按钮:进入theme目录,打开yilia目录下的 _config.yml 文件
修改 excerpt_link: 修改之后的more单词换成空格