hexo博客配置yilia主题

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单词换成空格

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值