使用环境变量配置hexo

在部署hexo博客的过程中,遇到这样一个问题:hexo的部署插件都是在配置文件中配置密钥,而我是使用GitHub Actions进行部署,配置文件也放在仓库中,就会导致部署密钥泄露,所以目前是使用了腾讯的COS部署插件实现,它可以在GitHub Actions中直接调用。

但还是想知道如何在hexo的层面上解决,所以在hexo仓库提交了一个issue

本来以为hexo目前还不支持,后来作者回复可以在自动化流程中使用config命令来实现:

1
2
export THEME=next
hexo config theme $THEME

我在hexo网站有搜了下文档,没有相关说明。但是这个命令可以使用:

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
37
38
39
40
❯ hexo -h  
INFO Validating config
Usage: hexo <command>

Commands:
clean Remove generated files and cache.
config Get or set configurations.
deploy Deploy your website.
generate Generate static files.
help Get help on a command.
init Create a new Hexo folder.
list List the information of the site
migrate Migrate your site from other system to Hexo.
new Create a new post.
publish Moves a draft post from _drafts to _posts folder.
render Render files with renderer plugins.
server Start the server.
version Display version information.

Global Options:
--config Specify config file instead of using _config.yml
--cwd Specify the CWD
--debug Display all verbose messages in the terminal
--draft Display draft posts
--safe Disable all plugins and scripts
--silent Hide output on console

For more help, you can use 'hexo help [command]' for the detailed information
or you can check the docs: http://hexo.io/docs/

❯ hexo help config
INFO Validating config
Usage: hexo config [name] [value]

Description:
Get or set configurations.

Arguments:
name Setting name. Leave it blank if you want to show all configurations.
value New value of a setting. Leave it blank if you just want to show a single configuration.

获取theme的配置:

1
2
3
❯ hexo config theme
INFO Validating config
next

如果需要设置某一项的子项,比如related_posts中的enable

1
2
3
❯ hexo config related_posts.enable
INFO Validating config
true