环境:
node.js 10.14.2
npm 6.4.1
hexo 3.8.0
NexT 6.6.0
Hexo常用命令
hexo clean && hexo g && hexo s -s
NexT 主题的使用
推荐新入坑的兄弟使用第一种方式来获取NexT主题。
主题配置文件
为了以后平滑升级,使用Hexo3.0的Data Files方式
NexT-Way
- 在
hexo/source/_data目录(没有的话新建一个)下新建next.yml文件。 - 把主题配置文件中的选项全部 copy 到
next.yml中。 - 在
next.yml文件中设置override选项为true。 - 在站点配置文件中修改
theme选项为next
主题设置
主题优化
头像旋转
单行注释使用//,多行使用/* */
修改/themes/next/source/css/_common/components/sidebar/sidebar-author.styl如下:
1 | .site-author-image { |
文章底部带#号的标签
修改模板/themes/next/layout/_macro/post.swig,搜索 rel="tag">#,将#换成<i class="fa fa-tag"></i>
在每篇文章末尾统一添加“本文结束”标记
- 在路径
\themes\next\layout\_macro中新建passage-end-tag.swig文件,并添加以下内容:
1 | <div> |
- 打开
\themes\next\layout\_macro\post.swig文件,在END POST BLOCK之后, 添加以下代码:
1 | <div> |
- 打开主题配置文件
next.yml,在末尾添加:
1 | # 文章末尾添加“本文结束”标记 |
主页文章加阴影
打开\themes\next\source\css\_custom\custom.styl,向里面加入:
1 | // 主页文章添加阴影效果 |
显示文章更新时间
修改主题配置文件的
1 | post_meta: |
要想具体显示到时分秒,则修改站点配置文件的
1 | date_format: YYYY-MM-DD HH:mm:ss |
代码添加复制按钮
下载
clipboard.js保存文件
clipboard.min.js到目录\themes\next\source\js\src在
.\themes\next\source\js\src目录下,创建clipboard-use.js,文件内容如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17/*页面载入完成后,创建复制按钮*/
!function (e, t, a) {
/* code */
var initCopyCode = function(){
var copyHtml = '';
copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
copyHtml += ' <i class="fa fa-globe"></i><span>copy</span>';
copyHtml += '</button>';
$(".highlight .code pre").before(copyHtml);
new ClipboardJS('.btn-copy', {
target: function(trigger) {
return trigger.nextElementSibling;
}
});
}
initCopyCode();
}(window, document);在
.\themes\next\source\css\_custom\custom.styl样式文件中添加下面代码:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36//代码块复制按钮
.highlight{
//方便copy代码按钮(btn-copy)的定位
position: relative;
}
.btn-copy {
display: inline-block;
cursor: pointer;
background-color: #eee;
background-image: linear-gradient(#fcfcfc,#eee);
border: 1px solid #d5d5d5;
border-radius: 3px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-webkit-appearance: none;
font-size: 13px;
font-weight: 700;
line-height: 20px;
color: #333;
-webkit-transition: opacity .3s ease-in-out;
-o-transition: opacity .3s ease-in-out;
transition: opacity .3s ease-in-out;
padding: 2px 6px;
position: absolute;
right: 5px;
top: 5px;
opacity: 0;
}
.btn-copy span {
margin-left: 5px;
}
.highlight:hover .btn-copy{
opacity: 1;
}在
.\themes\next\layout\_layout.swig文件中,添加引用(注:在 swig 末尾或 body 结束标签(</body>)之前添加):1
2
3<!-- 代码块复制功能 -->
<script type="text/javascript" src="/js/src/clipboard.min.js"></script>
<script type="text/javascript" src="/js/src/clipboard-use.js"></script>
文章加密
npm install --save hexo-blog-encrypt在站点配置文件下添加如下配置:
1
2encrypt:
enable: true在需要加密的文章的头部添加上对应的字段,如 password, abstract, message
1
2
3
4
5
password: Mike
abstract: Welcome to my blog, enter password to read.
message: Welcome to my blog, enter password to read.
二次元看板娘
npm install --save hexo-helper-live2dnpm install --save live2d-widget-model-wanko向站点配置文件中添加如下配置:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16live2d:
enable: true
scriptFrom: local
pluginRootPath: live2dw/
pluginJsPath: lib/
pluginModelPath: assets/
tagMode: false
debug: false
model:
use: live2d-widget-model-wanko
display:
position: right
width: 150
height: 300
mobile:
show: true注:在
next.yml中配置时,width, height等参数不起作用。
加载条
- 将
theme-next-pace克隆到本地一个空目录里。 - 删掉
pace目录下的.git文件夹 - 将
pace目录 copy 到themes/next/source/lib目录下 - 修改主题配置文件
next.yml的pace属性值为true
显示文章浏览进度百分比
在主题配置文件中修改属性sidebar下scrollpercent的值为true
文章预览
在文章中使用截断标记<!-- more -->手动指定文章预览的内容。
评论系统
Gitalk
Click here to sign up for a new OAuth Application
Application name: # 应用名称,随意,如
gitalk
Homepage URL: # 网站URL,如https://username.github.io,username是 GitHub 账户名
Application description # 描述,随意,如Comment System for Blog
Authorization callback URL:# 网站URL,https://username.github.io,username是 GitHub 账户名修改主题配置文件中的如下属性
1
2
3
4
5
6
7
8
9
10
11# Gitalk
# Demo: https://gitalk.github.io
# Reference: https://asdfv1929.github.io/2018/01/20/gitalk/, https://liujunzhou.cn/2018/8/10/gitalk-error/#more
gitalk:
enable: true
github_id: username # Github repo owner
repo: gitalk # Repository name to store issues.
client_id: ****** # Github Application Client ID
client_secret: ****** # Github Application Client Secret
admin_user: gzhennaxia # GitHub repo owner and collaborators, only these guys can initialize github issues
distraction_free_mode: true # Facebook-like distraction free mode
Valine
Create an account or log into LeanCloud, and then click on the bottom left corner to create the application in dashboard.
Go to the application you just created, select
Settings -> Apply Keyin the lower left corner, and you will see yourAPP IDandAPP Key.Set the value
enabletotrue, add the obtained APP ID (appid) and APP Key (appkey), and edit other configurations invalinesection in the theme config file as following:1
2
3
4
5
6
7
8
9
10
11
12
13
14# Valine.
# You can get your appid and appkey from https://leancloud.cn
# more info please open https://valine.js.org
valine:
enable: true # When enable is set to be true, leancloud_visitors is recommended to be closed for the re-initialization problem within different leancloud adk version.
appid: ****** # your leancloud application appid
appkey: ****** # your leancloud application appkey
notify: false # mail notifier , https://github.com/xCss/Valine/wiki
verify: false # Verification code
placeholder: Just go go # comment box placeholder
avatar: mm # gravatar style
guest_info: nick,mail,link # custom comment header
pageSize: 10 # pagination size
visitor: false # leancloud-counter-security is not supported for now. When visitor is set to be true, appid and appkey are recommended to be the same as leancloud_visitors' for counter compatibility. Article reading statistic https://valine.js.org/visitor.html
Gitalk + Valine双评论系统
在完成各自配置后对themes\next\layout\_partials\comments.swig做如下修改:
Before
1 | {% elseif theme.valine.enable and theme.valine.appid and theme.valine.appkey %} |
After
1 | {% elseif theme.gitalk.enable %} |
自动部署
踩坑记录
npm install warnings
1 | npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules/hexo-cli/node_modules/fsevents): |
解决方法
忽略就好
Hexo g error
1 | ERROR ENOENT: no such file or directory, open 'F:\Hexo\themes\next\layout\menu.swig' |
场景再现
从releases下载的 NexT 主题,然后再通过修改目录名为next的方式使用该主题的时候,生成文件的时候报的错。
报错原因
未知
解决方法
换用命令行下载的方式就不会报这个错了。