Hexo-NexT博客使用插件总结
引言
这几天将博客主题从 Fluid 换回了 NexT,在重新安装插件的时候顺便记录了本博客当前使用的插件以及插件相关的主题美化,便于后续修改和供NexT主题读者参考。
一键部署
地址
安装配置
安装插件:
1 | npm install hexo-deployer-git --save |
然后修改站点配置文件_config.yml 中的配置:
1 | # Deployment |
永久链接
地址
安装配置
安装插件:
1 | npm install hexo-abbrlink --save |
然后我们可以在站点配置文件_config.yml 中修改为:
1 | # URL |
文章推荐
这个可以帮助我们根据标签推荐相关文章,原版插件的使用要求编辑主题文件的,但是 NexT 主题集成了这个插件的配置,因此配置起来非常方便。
地址
安装配置
安装插件:
1 | npm install hexo-related-popular-posts --save |
我们只需要在主题配置文件_config.yml 中修改:
1 | # Related popular posts |
站点地图
通用站点地图
安装配置:
1 | npm install hexo-generator-sitemap --save |
然后我们需要在 Hexo 站点配置文件_config.yml 中加入 sitemap 插件:
1 | # 通用站点地图 |
百度站点地图
安装配置:
1 | npm install hexo-generator-baidu-sitemap --save |
具体配置类似通用站点地图,当然也可以看官方提供的教程,下面是一个简单的配置,我们在 Hexo 站点配置文件_config.yml 中添加:
1 | # 百度站点地图 |
百度推送
地址
安装配置
安装插件:
1 | npm install hexo-baidu-url-submit --save |
在站点配置文件_config.yml 中添加以下代码:
1 | # 百度主动推送 |
RSS订阅
地址
安装配置
1 | npm install hexo-generator-feed --save |
在站点的配置根目录_config.yml添加:
1 | # Extensions |
接着在主题配置文件添加:
1 | social: |
站点统计
地址
安装配置
1 | npm install hexo-symbols-count-time --save |
我们只需要在主题配置文件_config.yml 中修改:
1 | # Post wordcount display settings |
汉字的平均字符长度为 1.5,如果在文章中使用纯中文进行写作(没有混杂英文),那么推荐设置 awl: 2 及 wpm: 300,但是如果文章中存在英文,建议设置 awl: 4 及 wpm: 275。
文章置顶
插件配置
1 | npm uninstall hexo-generator-index --save |
图标配置
打开/themes/next/layout/_macro/ 目录下的post.swig文件,在<div class="post-meta">的第一个<span>标签下,插入如下代码:
1 | {% if post.top %} |
站内搜索
地址
安装配置
1 | npm install hexo-generator-searchdb --save |
在主题配置文件themes\next_config.yml中修改相关字段:
1 |
|
在站点配置文件_config.yml中添加以下字段:
1 | search: |
静态资源压缩
地址
安装配置
1 | npm install hexo-neat --save |
在站点配置文件_config.yml中添加以下字段:
1 | # hexo-neat |
图片懒加载
地址
安装配置
1 | npm install hexo-lazyload --save |
在站点配置文件_config.yml中添加以下字段:
1 | lazyload: |
文章标题翻译
地址
安装配置
1 | npm install hexo-translate-title --save |
配置 hexo 根项目下的 _config.yml:
1 | translate_title: |
修改 hexo 根目录下的 _config.yml:
1 | -permalink: :year/:month:day/:title.html |
将 :title 修改为 :translate_title 即可,前面的路径也可按照自己的要求变更,例如 permalink: blog/:translate_title.html。
外链优化
减少出站链接能够有效防止权重分散,hexo 有很方便的自动为出站链接添加 nofollow 标签的插件。
首先安装 hexo-filter-nofollow 插件:
1 | npm install hexo-filter-nofollow --save |
然后我们在站点的配置文件_config.yml 中添加配置,将 nofollow 设置为 true:
1 | # 外部链接优化 |
其中 exclude(例外的链接,比如友链)将不会被加上 nofollow 属性。
侧栏标签云
地址
安装配置
进入到 hexo 的根目录,然后在
package.json中添加依赖:"hexo-tag-cloud": "2.1.*"然后执行
npm install命令1
npm install hexo-tag-cloud
然后需要你去修改主题的 tagcloud 的模板,这个依据你的主题而定。
这里以 Next 主题为例,找到文件 next/layout/_macro/sidebar.swig, 然后添加如下内容。
1 | <div class="site-overview-wrap sidebar-panel"> |
侧栏 Celeste

这里以 Next 主题为例,找到文件 next/layout/_macro/sidebar.swig, 然后添加如下内容。
1 | <div class="twopeople"> |
PDF 展示
地址
安装配置
安装插件:
1 | npm install --save hexo-pdf |
使用方式;
Normal PDF
1 | {% pdf http://7xov2f.com1.z0.glb.clouddn.com/bash_freshman.pdf %} |
or
1 | {% pdf ./bash_freshman.pdf %} |
Google drive
1 | {% pdf https://drive.google.com/file/d/0B6qSwdwPxPRdTEliX0dhQ2JfUEU/preview %} |
Slideshare
1 | {% pdf http://www.slideshare.net/slideshow/embed_code/key/8Jl0hUt2OKUOOE %} |
效果预览
Normal PDF

Google drive

Slideshare

Live2D
地址
安装配置
1 | npm install --save hexo-helper-live2d |
选择模型
可到https://huaji8.top/post/live2d-plugin-2.0/预览效果。
命令为:npm install live2d-widget-model-模型名,模型为可参考上面的预览内容,安装模型:
1 | npm install live2d-widget-model-hijiki |
主题配置
站点的配置文件\_config.yml或者是主题的配置文件中添加:
1 | # Live2D |
参考
播放器标签
地址
安装
1 | npm install hexo-tag-aplayer --save |
Aplayer
依赖
- APlayer.js > 1.8.0
- Meting.js > 1.1.1
使用
1 | {% aplayer title author url [picture_url, narrow, autoplay, width:xxx, lrc:xxx] %} |
标签参数
title: 曲目标题author: 曲目作者url: 音乐文件 URL 地址picture_url: (可选) 音乐对应的图片地址narrow: (可选)播放器袖珍风格autoplay: (可选) 自动播放,移动端浏览器暂时不支持此功能width:xxx: (可选) 播放器宽度 (默认: 100%)lrc:xxx: (可选)歌词文件 URL 地址
当开启 Hexo 的 文章资源文件夹 功能时,可以将图片、音乐文件、歌词文件放入与文章对应的资源文件夹中,然后直接引用:
1 | {% aplayer "Caffeine" "Jeff Williams" "caffeine.mp3" "picture.jpg" "lrc:caffeine.txt" %} |
歌词标签
除了使用标签 lrc 选项来设定歌词,你也可以直接使用 aplayerlrc 标签来直接插入歌词文本在博客中:
1 | {% aplayerlrc "title" "author" "url" "autoplay" %} |
播放列表
1 | {% aplayerlist %} |
MeingJS 支持 (3.0 新功能)
MetingJS 是基于Meting API 的 APlayer 衍生播放器,引入 MetingJS 后,播放器将支持对于 QQ音乐、网易云音乐、虾米、酷狗、百度等平台的音乐播放。
如果想在本插件中使用 MetingJS,请在 Hexo 配置文件 _config.yml 中设置:
1 | aplayer: |
接着就可以通过 {% meting ...%} 在文章中使用 MetingJS 播放器了:
1 | <!-- 简单示例 (id, server, type) --> |
有关 {% meting %} 的选项列表如下:
| 选项 | 默认值 | 描述 |
|---|---|---|
| id | 必须值 | 歌曲 id / 播放列表 id / 相册 id / 搜索关键字 |
| server | 必须值 | 音乐平台: netease, tencent, kugou, xiami, baidu |
| type | 必须值 | song, playlist, album, search, artist |
| fixed | false |
开启固定模式 |
| mini | false |
开启迷你模式 |
| loop | all |
列表循环模式:all, one,none |
| order | list |
列表播放模式: list, random |
| volume | 0.7 | 播放器音量 |
| lrctype | 0 | 歌词格式类型 |
| listfolded | false |
指定音乐播放列表是否折叠 |
| storagename | metingjs |
LocalStorage 中存储播放器设定的键名 |
| autoplay | true |
自动播放,移动端浏览器暂时不支持此功能 |
| mutex | true |
该选项开启时,如果同页面有其他 aplayer 播放,该播放器会暂停 |
| listmaxheight | 340px |
播放列表的最大长度 |
| preload | auto |
音乐文件预载入模式,可选项: none, metadata, auto |
| theme | #ad7a86 |
播放器风格色彩设置 |
关于如何设置自建的 Meting API 服务器地址,以及其他 MetingJS 配置,请参考章节自定义配置
PJAX 兼容
若在 Hexo 中使用了 PJAX,可能需要自己手动清理 APlayer 全局实例:
1 | $(document).on('pjax:start', function () { |
自定义配置(3.0 新功能)
现在你可以在 Hexo 配置文件 _config.yml 中配置本插件:
1 | aplayer: |
Dplayer
快速开始
我们先尝试初始化一个最简单的 DPlayer
加载播放器文件:
1 | <div id="dplayer"></div> |
或者使用模块管理器:
1 | import DPlayer from 'dplayer'; |
在 js 里初始化:
1 | const dp = new DPlayer({ |
一个最简单的 DPlayer 就初始化好了,它只有最基本的视频播放功能
参数
DPlayer 有丰富的参数可以自定义你的播放器实例
| 名称 | 默认值 | 描述 |
|---|---|---|
| container | document.querySelector(‘.dplayer’) | 播放器容器元素 |
| live | false | 开启直播模式, 见#直播 |
| autoplay | false | 视频自动播放 |
| theme | ‘#b7daff’ | 主题色 |
| loop | false | 视频循环播放 |
| lang | navigator.language.toLowerCase() | 可选值: ‘en’, ‘zh-cn’, ‘zh-tw’ |
| screenshot | false | 开启截图,如果开启,视频和视频封面需要允许跨域 |
| hotkey | true | 开启热键,支持快进、快退、音量控制、播放暂停 |
| airplay | true | 在 Safari 中开启 AirPlay |
| preload | ‘auto’ | 视频预加载,可选值: ‘none’, ‘metadata’, ‘auto’ |
| volume | 0.7 | 默认音量,请注意播放器会记忆用户设置,用户手动设置音量后默认音量即失效 |
| playbackSpeed | [0.5, 0.75, 1, 1.25, 1.5, 2] | 可选的播放速率,可以设置成自定义的数组 |
| logo | - | 在左上角展示一个 logo,你可以通过 CSS 调整它的大小和位置 |
| apiBackend | - | 自定义获取和发送弹幕行为,见#直播 |
| video | - | 视频信息 |
| video.quality | - | 见#清晰度切换 |
| video.defaultQuality | - | 见#清晰度切换 |
| video.url | - | 视频链接 |
| video.pic | - | 视频封面 |
| video.thumbnails | - | 视频缩略图,可以使用 DPlayer-thumbnails (opens new window)生成 |
| video.type | ‘auto’ | 可选值: ‘auto’, ‘hls’, ‘flv’, ‘dash’, ‘webtorrent’, ‘normal’ 或其他自定义类型, 见#MSE 支持 |
| video.customType | - | 自定义类型, 见#MSE 支持 |
| subtitle | - | 外挂字幕 |
| subtitle.url | required |
字幕链接 |
| subtitle.type | ‘webvtt’ | 字幕类型,可选值: ‘webvtt’, ‘ass’,目前只支持 webvtt |
| subtitle.fontSize | ‘20px’ | 字幕字号 |
| subtitle.bottom | ‘40px’ | 字幕距离播放器底部的距离,取值形如: ‘10px’ ‘10%’ |
| subtitle.color | ‘#fff’ | 字幕颜色 |
| danmaku | - | 显示弹幕 |
| danmaku.id | required |
弹幕池 id,必须唯一 |
| danmaku.api | required |
见#弹幕接口 |
| danmaku.token | - | 弹幕后端验证 token |
| danmaku.maximum | - | 弹幕最大数量 |
| danmaku.addition | - | 额外外挂弹幕,见#bilibili 弹幕 |
| danmaku.user | ‘DIYgod’ | 弹幕用户名 |
| danmaku.bottom | - | 弹幕距离播放器底部的距离,防止遮挡字幕,取值形如: ‘10px’ ‘10%’ |
| danmaku.unlimited | false | 海量弹幕模式,即使重叠也展示全部弹幕,请注意播放器会记忆用户设置,用户手动设置后即失效 |
| contextmenu | [] | 自定义右键菜单 |
| highlight | [] | 自定义进度条提示点 |
| mutex | true | 互斥,阻止多个播放器同时播放,当前播放器播放时暂停其他播放器 |
1 | const dp = new DPlayer({ |
API
dp.play(): 播放视频dp.pause(): 暂停视频dp.seek(time: number): 跳转到特定时间1
dp.seek(100);
dp.toggle(): 切换播放和暂停dp.on(event: string, handler: function): 绑定视频和播放器事件,见#事件绑定dp.switchVideo(video, danmaku): 切换到其他视频1
2
3
4
5
6
7
8
9
10
11
12
13dp.switchVideo(
{
url: 'second.mp4',
pic: 'second.png',
thumbnails: 'second.jpg',
},
{
id: 'test',
api: 'https://api.prprpr.me/dplayer/',
maximum: 3000,
user: 'DIYgod',
}
);dp.notice(text: string, time: number): 显示通知,时间的单位为毫秒,默认时间 2000 毫秒,默认透明度 0.8dp.switchQuality(index: number): 切换清晰度dp.destroy(): 销毁播放器dp.speed(rate: number): 设置视频速度dp.volume(percentage: number, nostorage: boolean, nonotice: boolean): 设置视频音量1
dp.volume(0.1, true, false);
dp.video: 原生 videodp.video.currentTime: 返回视频当前播放时间dp.video.duration: 返回视频总时间dp.video.paused: 返回视频是否暂停dp.danmakudp.danmaku.send(danmaku, callback: function): 提交一个新弹幕1
2
3
4
5
6
7
8
9
10dp.danmaku.send(
{
text: 'dplayer is amazing',
color: '#b7daff',
type: 'right', // should be `top` `bottom` or `right`
},
function () {
console.log('success');
}
);dp.danmaku.draw(danmaku): 实时绘制一个新弹幕1
2
3
4
5dp.danmaku.draw({
text: 'DIYgod is amazing',
color: '#fff',
type: 'top',
});dp.danmaku.opacity(percentage: number): 设置弹幕透明度,透明度值在 0 到 1 之间1
dp.danmaku.opacity(0.5);
dp.danmaku.clear(): 清除所有弹幕dp.danmaku.hide(): 隐藏弹幕dp.danmaku.show(): 显示弹幕dp.fullScreen: 两个类型:web和browser,默认类型是browserdp.fullScreen.request(type: string): 进入全屏1
dp.fullScreen.request('web');
dp.fullScreen.cancel(type: string): 退出全屏1
dp.fullScreen.cancel('web');
事件绑定
1 | dp.on(event, handler) |
视频事件
- abort
- canplay
- canplaythrough
- durationchange
- emptied
- ended
- error
- loadeddata
- loadedmetadata
- loadstart
- mozaudioavailable
- pause
- play
- playing
- progress
- ratechange
- seeked
- seeking
- stalled
- suspend
- timeupdate
- volumechange
- waiting
播放器事件
- screenshot
- thumbnails_show
- thumbnails_hide
- danmaku_show
- danmaku_hide
- danmaku_clear
- danmaku_loaded
- danmaku_send
- danmaku_opacity
- contextmenu_show
- contextmenu_hide
- notice_show
- notice_hide
- quality_start
- quality_end
- destroy
- resize
- fullscreen
- fullscreen_cancel
- subtitle_show
- subtitle_hide
- subtitle_change
清晰度切换
在 video.quality 里设置不同清晰度的视频链接和类型,video.defaultQuality 设置默认清晰度
Load demo
1 | const dp = new DPlayer({ |
弹幕
弹幕接口
1 | danmaku.api |
现成的接口
链接: https://api.prprpr.me/dplayer/
每日备份: DPlayer-data(opens new window)
自己搭建
DPlayer-node(opens new window)
bilibili 弹幕
1 | danmaku.addition |
API: https://api.prprpr.me/dplayer/v3/bilibili?aid=[aid](opens new window)
1 | const option = { |
Hexo管理器
地址
安装配置
安装插件:
1 | npm install --save hexo-admin |


密码设置
If you’re using Hexo admin on your live server, you want some password protection. To enable this, you just add a few config variables to your hexo _config.yml:
1 | admin: |
The password_hash is the bcrypt hash of your password. The secret is used to make the cookies secure, so it’s a good idea to have it be long and complicated.
A utility in Hexo admin’s Settings can hash your password and generate the admin section for you. Start Hexo and go to Settings > Setup authentification and fill out your information. Copy the generated YAML into your _config.yml.
Once that’s in place, start up your hexo server and going to /admin/ will require you to enter your password.
NexT主题文档
地址
安装配置
Install Hexo & NexT & NexT Website Source on Localhost:
1 | git clone https://github.com/next-theme/theme-next-docs |
Generate:
1 | npx hexo generate |
Run server:
1 | npx hexo server |
又拍云部署
地址
安装配置
编辑根目录的 _config.yml 文件的 deploy 字段,配置又拍云存储的服务名称、操作员名称、操作员密码:
1 | deploy: |
Netlify CMS
地址
安装配置
这是一个 Netlify CMS 的 Hexo 插件,你可以使用它,简单的开启 Netlify CMS 服务。
1 | cnpm install --save hexo-netlify-cms |
设置自定义配置文件,覆盖默认的,自定义配置文件的定义变量与 hexo 配置文件的 netlify_cms 变量中定义的等效
1 | netlify_cms: |
设置 post 与 page 自动生成器:
1 | auto_generator: |
设置全局的 fields:
1 | global_fields: |
添加脚本, 用于自定义组件和预览样式:
1 | netlify_cms: |
Hexo Next 暗黑模式
适用于 NexT 主题的暗黑/夜间模式切换插件。
地址
安装配置
1 | npm install hexo-next-darkmode --save |
首先确保 NexT 主题原生的 darkmode 选项设置为 false:
1 | # Close NexT's darkmode |
往 NexT 主题的 _config.yml 配置文件里添加以下内容:
1 | # Darkmode JS |
isActivated: true:默认激活暗黑/夜间模式,请始终与saveInCookies: false、autoMatchOsTheme: false一起使用;同时需要在 NexT 主题的_config.yml配置文件里设置pjax: true,即启用 Pjax。
