hexo更多花样玩法

📋

修改文章底部的那个带#号的标签

实现效果图看文章底部标签

具体实现方法:

修改模板/themes/next/layout/_macro/post.swig,搜索

1
rel="tag">#,将 # 换成<i class="fa fa-tags"></i>

设置网站的图标Favicon

实现效果图

具体方法实现:

EasyIcon中找一张(32*32)的ico图标,或者去别的网站下载或者制作,并将图标名称改为favicon.ico,然后把图标放在/themes/next/source/images里,并且修改主题配置文件:

Put your favicon.ico into hexo-site/source/ directory.
favicon: /images/favicon.ico

添加 README.md 文件

每个项目下一般都有一个 README.md 文件,但是使用 hexo 部署到仓库后,项目下是没有 README.md 文件的。

在 Hexo 目录下的 source 根目录下添加一个 README.md 文件,修改站点配置文件 _config.yml,将 skip_render 参数的值设置为

skip_render: README.md
保存退出即可。再次使用 hexo d 命令部署博客的时候就不会在渲染 README.md 这个文件了。

修改网页底部的黑桃心

还是打开themes/next/layout/_partials/footer.swig,找到:

1
2
<span class="with-love">
<i class="fa fa-star"></i>

图标库找到你自己喜欢的图标,然后修改star的部分内容就可以了。

修改字体大小

打开\themes\next\source\css\ _variables\base.styl文件,将$font-size-base改成16px,如下所示:

$font-size-base =16px

Hexo去掉底部强力驱动及主题字样

找到 \themes\next\layout_partials\下面的footer.swig文件,打开:

1
2
3
4
5
6
7
8
9
<div class="powered-by">
{{ __('footer.powered', '<a class="theme-link" href="https://hexo.io">Hexo</a>') }}
</div>
<div class="theme-info">
{{ __('footer.theme') }} -
<a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
NexT.{{ theme.scheme }}
</a>
</div>

第一条是“由Hexo驱动” 的Hexo链接,把xml段删除,只留两个单引号’’。

第二条是“主题-Next.XX”,将xml段都删掉,不留引号。

1
2
3
4
5
6
<div class="powered-by">
{{ __('footer.powered', '') }}
</div>
<div class="theme-info">
{{ __('footer.theme') }}
</div>

找到这个地方\themes\next\languages\ 下面的语言文件zh-Hans.yml(以中文为例):

footer:
powered: “由 %s 强力驱动”
theme: 主题
将上面的文字改成自己想要的即可。

文章置顶

在hexo github 的issue里找到了解决办法,解决Hexo置顶问题,只需两步:
1、用文章中的js代码替换node_modules/hexo-generator-index/lib/generator.js (见下文代码段),修改前最好备份一下
2、在需要置顶的文章的front-matter中添加top值,值越大越置顶。


title: 某文章
date:
top: 1000


以下是最终的node_modules/hexo-generator-index/lib/generator.js

‘use strict’;
var pagination = require(‘hexo-pagination’);
module.exports = function(locals){
var config = this.config;
var posts = locals.posts;
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; // 都没定义按照文章日期降序排
});
var paginationDir = config.pagination_dir || ‘page’;
return pagination(‘’, posts, {
perPage: config.index_generator.per_page,
layout: [‘index’, ‘archive’],
format: paginationDir + ‘/%d/‘,
data: {
__index: true
}
});
};

谢谢观看!

End