将 Hexo 升级到 v5.0.0

感觉刚刚才升级到 Hexo 4.2.1 没多久,结果 Hexo 又双叒叕更新了……

而且这次升级还是大版本号升级,说不定有惊喜? 本着好奇害死猫的精神,果断升级之!

之前升级的时候,写了篇文章同步在「知乎」,然后有小伙伴留言说可以用 ncu -u 一把梭。

有这种好事岂能错过?简单搜索了一下,就领悟到了要点:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ npm install npm-check-updates -g
$ ncu
Checking /Users/tommy/blog/package.json
[====================] 16/16 100%

hexo ^4.2.0 → ^5.0.0
hexo-generator-sitemap ^2.0.0 → ^2.1.0

Run ncu -u to upgrade package.json
$ ncu -u
Upgrading /Users/tommy/blog/package.json
[====================] 16/16 100%

hexo ^4.2.0 → ^5.0.0
hexo-generator-sitemap ^2.0.0 → ^2.1.0

Run npm install to install new versions.

简单如此,就把 package.json 文件给更新了,果然是一把梭啊,爽~~~

对于强迫症的我,习惯性删除重来是必须的!

1
2
$ rm -fr node_modules/
$ npm install --save

顺手升级一下 CLI:

1
2
3
4
$ npm install hexo-cli -g
/usr/local/bin/hexo -> /usr/local/lib/node_modules/hexo-cli/bin/hexo
+ [email protected]
added 1 package from 1 contributor, removed 21 packages and updated 13 packages in 4.121s

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$ hexo version
INFO Validating config
hexo: 5.0.0
hexo-cli: 4.1.0
os: Darwin 19.6.0 darwin x64
node: 12.18.3
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

既然是大版本升级,绝对不可能这么简简单单一升级就 OK 的。

以我多年来瞎折腾的经验看,肯定还有坑。

运行 hexo server 验证一下我的想法,果不其然:

1
2
INFO  Validating config
WARN Deprecated config detected: "external_link" with a Boolean value is deprecated. See https://hexo.io/docs/configuration for more details.

嗯……「deprecated」啊……查一下官方的 Release Note

果然有个叫「Breaking change」的东东,里面就有说到配置文件的变化。

_config.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
# Deprecated
external_link: true|false

# New option
external_link:
enable: true|false

# Deprecated
use_date_for_updated: true

# New option
# https://hexo.io/docs/configuration#Date-Time-format
updated_option: date

对比以后,发现主要有如下变化,大家根据自己的需要调整修改就好了:

_config.yml
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
pretty_urls:
trailing_index: true # Set to false to remove trailing 'index.html' from permalinks
trailing_html: true # Set to false to remove trailing '.html' from permalinks

external_link:
enable: true # Open external links in new tab
field: site # Apply to the whole site
exclude: ''

prismjs:
enable: false
preprocess: true
line_number: true
tab_replace: ''

# Metadata elements
## https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta
meta_generator: true

# updated_option supports 'mtime', 'date', 'empty'
updated_option: 'mtime'

# Include / Exclude file(s)
## include:/exclude: options only apply to the 'source/' folder
include:
exclude:
ignore:

简单调整后,Hexo 已经可以正常使用了。

暂时还没有体会到 Hexo 5.0.0 有什么特别不同的地方,再慢慢体会一下吧。