将 Hexo 升级到 v4.2.1

当您见到这篇文章的时候,就表示我又有很久没有写过文章,所以需要更新系统了。

不得不说,Node.js 的更新速度实在是太快了,我连 LTS 的脚步都跟不上啊。每次都是升级 LTS 版本,可是隔三差五就还得升级。

Hexo 有段时间升级不怎么积极,这次一看,嘿,厉害了,大版本号都升级了!于是乎从上到下都升级了一遍。

升级 Node.js

最新的 Node.js 稳定版本已经更新到了 v12.18.2

升级前的版本是 Node.js v10.16.3,也算是长期稳定版本了。但是本着有新不用旧的暴发户心态,果断升级之。😅

n 来检查并升级到最新版本:

1
2
3
4
5
6
7
$ n lts

installing : node-v12.18.2
mkdir : /usr/local/n/versions/node/12.18.2
fetch : https://nodejs.org/dist/v12.18.2/node-v12.18.2-darwin-x64.tar.xz
installed : v12.18.2 (with npm 6.14.5)

就这么简单就安装完了,毫无惊喜,毫无悬念:

1
2
3
$ n ls
node/10.16.3
node/12.18.2

升级 Hexo

进入 Hexo 的目录,检查一下有哪些 Package 已经过期了:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ npm outdated
Package Current Wanted Latest Location
eslint 6.1.0 6.8.0 7.4.0 hexo-site
hexo 3.9.0 3.9.0 4.2.1 hexo-site
hexo-deployer-git 1.0.0 1.0.0 2.1.0 hexo-site
hexo-deployer-rsync 0.1.3 0.1.3 1.0.0 hexo-site
hexo-generator-archive 0.1.5 0.1.5 1.0.0 hexo-site
hexo-generator-category 0.1.3 0.1.3 1.0.0 hexo-site
hexo-generator-feed 1.2.2 1.2.2 2.2.0 hexo-site
hexo-generator-index 0.2.1 0.2.1 1.0.0 hexo-site
hexo-generator-sitemap 1.2.0 1.2.0 2.0.0 hexo-site
hexo-generator-tag 0.2.0 0.2.0 1.0.0 hexo-site
hexo-renderer-ejs 0.3.1 0.3.1 1.0.0 hexo-site
hexo-renderer-marked 1.0.1 1.0.1 3.0.0 hexo-site
hexo-renderer-stylus 0.3.3 0.3.3 1.1.0 hexo-site
hexo-server 0.3.3 0.3.3 1.0.0 hexo-site
hexo-symbols-count-time 0.6.0 0.6.3 0.7.1 hexo-site

根据上面的信息修改一下 package.json 文件:

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
{
"name": "hexo-site",
"version": "0.0.0",
"private": true,
"hexo": {
"version": "4.2.1"
},
"dependencies": {
"hexo": "^4.2.0",
"hexo-deployer-git": "^2.1.0",
"hexo-deployer-rsync": "^1.0.0",
"hexo-generator-archive": "^1.0.0",
"hexo-generator-category": "^1.0.0",
"hexo-generator-feed": "^2.2.0",
"hexo-generator-index": "^1.0.0",
"hexo-generator-search": "^2.4.0",
"hexo-generator-seo-friendly-sitemap": "0.0.25",
"hexo-generator-sitemap": "^2.0.0",
"hexo-generator-tag": "^1.0.0",
"hexo-renderer-ejs": "^1.0.0",
"hexo-renderer-marked": "^3.0.0",
"hexo-renderer-stylus": "^1.1.0",
"hexo-server": "^1.0.0",
"hexo-symbols-count-time": "^0.7.1"
}
}

反正就是根据 npm 反馈的版本号对应修改一下就好了。全部改好了以后,就 npm 更新一下:

1
$ npm install --save

为了减少不必要的垃圾和冲突,我在执行上述命令之前删除了 node_modules 目录:

1
$ rm -fr node_modules

搞掂,检查一下版本信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$ hexo version
hexo: 4.2.1
hexo-cli: 2.0.0
os: Darwin 19.5.0 darwin x64
node: 12.18.2
v8: 7.8.279.23-node.39
uv: 1.38.0
zlib: 1.2.11
brotli: 1.0.7
ares: 1.16.0
modules: 72
nghttp2: 1.41.0
napi: 6
llhttp: 2.0.4
http_parser: 2.9.3
openssl: 1.1.1g
cldr: 37.0
icu: 67.1
tz: 2019c
unicode: 13.0

更新 Hexo CLI

接着运行,发现 Hexo 命令行显示乱码(换行不正确),检查一下有无新版本:

1
2
3
$ npm outdated -g
Package Current Wanted Latest Location
hexo-cli 2.0.0 2.0.0 3.1.0 global

嗯,果然是有新版本的,升级之:

1
2
3
4
5
npm install hexo-cli -g
npm WARN deprecated hexo-bunyan@2.0.0: Please see https://github.com/hexojs/hexo-bunyan/issues/17
/usr/local/bin/hexo -> /usr/local/lib/node_modules/hexo-cli/bin/hexo
+ hexo-cli@3.1.0
added 23 packages from 10 contributors, removed 196 packages and updated 32 packages in 9.859s

重新运行 Hexo 命令,一切正常。

更新主题

盐鹅,我还是太天真了,生成页面一看,hmm…. 页面各种显示不正常,看来主题也得更新。

最新的 NexT 主题已经更新到了 v7.8.0,当前正在使用的版本是 v7.2.0。

因为增加删除了不少的东西,所以配置起来比较麻烦。主要是配置文件 _config.yml 变化太大啦,最后只能用 Beyond Compare 一点点比较,一点点调整了。

更新完主题以后,一切正常,你现在看到的这篇文章就是全部调整以后的结果了。