最近对博客主题进行了一次升级,顺便在这里记录一下本博客使用的插件,做个备忘。

插件 功能 版本
hexo-deployer-git 一键部署 ^2.1.0
hexo-symbols-count-time 字数统计与阅读时长 ^0.7.1
hexo-generator-searchdb 本地搜索 ^1.2.0
hexo-abbrlink url 持久化 ^2.0.5
hexo-filter-nofollow 减少出站链接 ^2.0.2
hexo-baidu-url-submit 百度推送 ^0.0.6
hexo-generator-baidu-sitemap 百度站点地图 ^0.1.6
hexo-generator-index-pin-top 置顶 ^0.2.2
hexo-neat 博文压缩 ^1.0.4
hexo-related-popular-posts 相关文章推荐 ^4.0.0
hexo-cake-moon-menu 返回按钮 ^2.1.0
hexo-generator-sitemap 站点地图 ^2.0.0
hexo-filter-emoji emoji 表情支持 ^2.2.1
hexo-generator-archive ^1.0.0
hexo-generator-category ^1.0.0
hexo-generator-index ^1.0.0
hexo-generator-tag ^1.0.0
hexo-renderer-ejs ^1.0.0
hexo-renderer-stylus ^1.1.0
hexo-renderer-marked ^2.0.0
hexo-server ^1.0.0

注意:目前我以采用数据文件的方式进行更新,下文所指的主题配置文件,现在均指hexo/soure/_data/next.yml

Hexo 一键部署插件

地址

安装配置

安装插件:

1
npm install hexo-deployer-git --save

然后修改站点配置文件 中的配置:

1
2
3
4
deploy:
- type: git
repository: git@github.com:constown/constown.github.io.git
branch: master

字数和阅读时间统计插件

地址

安装配置

安装插件:

1
npm install hexo-symbols-count-time --save

站点配置文件 中添加以下代码:

1
2
3
4
5
6
7
8
9
10
11
symbols_count_time:
#文章内是否显示
symbols: true
time: false
# 网页底部是否显示
total_symbols: true
total_time: false
exclude_codeblock: false
awl: 4
wpm: 275
suffix: 'mins.'

然后由于此插件集成在 NexT 中,然后修改主题配置文件

1
2
3
4
5
# 文章字数统计
symbols_count_time:
separated_meta: true
item_text_post: true
item_text_total: false

Hexo 本地搜索功能

插件地址

安装配置

安装插件:

1
npm install hexo-generator-searchdb --save

然后我们修改站点配置文件,添加如下内容:

1
2
3
4
5
6
# 本地搜索
search:
path: search.xml
field: post
format: html
limit: 100
  • path:索引文件的路径,相对于站点根目录
  • field:搜索范围,默认是 post,还可以选择 page、all,设置成 all 表示搜索所有页面
  • limit:限制搜索的条目数

然后修改主题配置文件

1
2
3
4
5
6
local_search:
enable: true
trigger: auto
top_n_per_article: 1
unescape: false
preload: true

Hexo 文章永久链接插件

地址

安装配置

安装插件:

1
npm install hexo-abbrlink --save

然后我们可以在站点配置文件中修改为:

1
2
3
4
5
6
7
8
9
10
11
# URL
url: https://blog.juanertu.com
root: /
permalink: archives/:abbrlink.html
permalink_defaults:
pretty_urls:
trailing_index: true
trailing_html: true
abbrlink:
alg: crc32 # 算法:crc16(default) and crc32
rep: hex # 进制:dec(default) and hex

Hexo 减少出站链接

地址

安装配置

安装插件:

1
npm install hexo-filter-nofollow --save

再在站点配置文件中添加配置,将 nofollow 设置为 true

1
2
3
4
5
6
nofollow:
enable: true
field: site
exclude:
- 'exclude1.com'
- 'exclude2.com'

这样,例外的链接将不会被加上 nofollow 属性。

Hexo 百度主动推送

地址

安装配置

安装插件:

1
npm install hexo-baidu-url-submit --save

站点配置文件中添加以下代码:

1
2
3
4
5
6
# 百度主动推送
baidu_url_submit:
count: 5 ## 提交最新的1个链接
host: tding.top ## 百度站长平台中注册的域名
token: ## 准入秘钥
path: baidu_urls.txt ## 文本文档的地址, 新链接会保存在此文本文档里

Hexo 站点地图 sitemap 生成

通用站点地图

安装配置:

1
npm install hexo-generator-sitemap --save

然后我们需要在 Hexo 站点配置文件中加入 sitemap 插件:

1
2
3
# 通用站点地图
sitemap:
path: sitemap.xml

百度站点地图

安装配置:

1
npm install hexo-generator-baidu-sitemap --save

具体配置类似通用站点地图,当然也可以看官方提供的教程,下面是一个简单的配置,我们在 Hexo 站点配置文件中添加:

1
2
3
# 百度站点地图
baidusitemap:
path: baidusitemap.xml

Hexo 文章置顶插件

地址

安装配置

安装插件:

1
2
npm uninstall hexo-generator-index --save #卸载原来的插件
npm install hexo-generator-index-pin-top --save

在需要置顶的文章的 Front-matter 中加上 top: true 或者 top: 任意数字,比如:

1
2
3
4
5
title: 谢谢你来看我的博客
top: true
header: false
abbrlink: a8863134
date: 2020-02-01 12:10:10

注意:top 中数字越大,文章越靠前

设置置顶图标

打开 /themes/next/layout/_macro/ 目录下的 post.swig 文件,在 的第一个 标签下,插入如下代码:

更新为将此代码放置到hexo/source/_data/post-meta.swig 文件中

1
2
3
4
5
{% if post.top %}
<i class="fa fa-thumb-tack"></i>
<font color=7D26CD>置顶</font>
<span class="post-meta-divider">|</span>
{% endif %}

next.yml 设置

1
2
3
custom_file_path:
- #postMeta: source/_data/post-meta.swig
+ postMeta: source/_data/post-meta.swig

Hexo 页面静态资源压缩插件

地址

安装配置

安装 hexo-neat 插件

安装插件:

1
npm install hexo-neat --save

站点配置文件添加相关配置

然后我们需要在站点配置文件中添加以下代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 博文压缩
neat_enable: true
# 压缩html
neat_html:
enable: true
exclude:
# 压缩css
neat_css:
enable: true
exclude:
- '**/*.min.css'
# 压缩js
neat_js:
enable: false
mangle: true
output:
compress:
exclude:
- '**/*.min.js'
- '**/jquery.fancybox.pack.js'
- '**/index.js'
- '**/fireworks.js'

Hexo 推荐文章插件

地址

安装配置

安装插件:

1
npm install hexo-related-popular-posts --save

我们只需要在主题配置文件中修改:

1
2
3
4
5
6
7
8
9
10
related_posts:
enable: true
title: 相关文章推荐 # Custom header, leave empty to use the default one
display_in_home: false
params:
maxCount: 5
PPMixingRate: 0.25
isDate: false
isImage: false
isExcerpt: false

Hexo 修改 back2top 标签

地址

安装配置

安装插件:

1
npm install hexo-cake-moon-menu --save

然后在站点配置文件``_config.yml 中添加以下代码:

1
2
3
4
5
6
7
8
9
10
11
moon_menu:
back2top:
enable: true
icon: fa fa-chevron-up
func: back2top
order: -1
back2bottom:
enable: true
icon: fa fa-chevron-down
func: back2bottom
order: -2

Hexo 添加 emoji 表情支持

地址

安装配置

  • 安装插件
1
npm install hexo-filter-emoji
  • 站点配置文件 .config.yml 中增加:
1
2
3
4
5
emoji:
enable: true
className: github-emoji
styles:
customEmojis:

参考资料

插件汇总