Hexo博客本地部署
ssk-wh Lv4

在本地快速预览博客部署效果,可按照此步骤操作。否则直接向源文件仓库中提交 md 文档即可。

安装软件包

sudo apt install npm
uos系统中的默认版本有点问题,无法通过npm安装其他包(如果您的版本没问题,直接跳到下一下节),可按照 nodesourceREADME 更新 nodejs.
或按照以下步骤(适合 Debian 系的 Linux 发行版):
sudo apt-get install -y curl
curl -fsSL https://deb.nodesource.com/setup_20.x -o nodesource_setup.sh
sudo -E bash nodesource_setup.sh
sudo apt-get install -y nodejs

安装成功后,通过 node -v 查看安装后的版本

1
2
> node -v
v20.13.1

预览

cd your_hexo_dir
npm install hexo
阿拉的电脑已经安装过了,所以安装结果如下:

1
2
3
4
5
6
7
8
> npm install hexo
npm notice Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/
npm notice Beginning October 4, 2021, all connections to the npm registry - including for package installation - must use TLS 1.2 or higher. You are currently using plaintext http to connect. Please visit the GitHub blog for more information: https://github.blog/2021-08-23-npm-registry-deprecating-tls-1-0-tls-1-1/

up to date in 2s

22 packages are looking for funding
run `npm fund` for details

此时正常情况下可以使用 npm hexo servernpm run server 查看预览效果

如果碰到 npm 不识别 hexo 命令的情况,请自行配置 npm 的环境变量,或者找到当前安装的 hexo 命令所在,一般在当前安装目录的 node_modules/hexo/bin/ 下,之后执行即可,例如 ./node_modules/hexo/bin/hexo s

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
uos@uos-PC ~ ./node_modules/hexo/bin/hexo s
INFO Validating config
INFO
------------------------------------------
__ ___ _______ _______ .______
| |/ / | ____|| ____|| _ \
| ' / | |__ | |__ | |_) |
| < | __| | __| | ___/
| . \ | |____ | |____ | |
|__|\__\ |_______||_______|| _|

------------------------------------------
Keep version 4.1.2
Documentation: https://keep-docs.xpoet.cn
------------------------------------------

INFO Start processing
INFO url_submission: Start generating url list...
INFO url_submission: Page urls will generate into file named submit_url.txt
INFO Hexo is running at http://localhost:4000/ . Press Ctrl+C to stop.

之后在浏览器中访问 [http://localhost:4000/] 就可以看到预览效果了.

后期如果只是为了提交新文章,只需要 clone 对应的项目到本地,在 source/_posts 目录下新建文档即可。提交后由经由 github actions 自动部署并发布。

问题

npm 执行时提示不存在 package.json 文件,执行 npm init 进行初始化。再执行你要执行的操作,如 npm install hexo
详情可参考https://blog.csdn.net/weixin_40161974/article/details/99441501

附录

hexo官方说明

 Comments
Comment plugin failed to load
Loading comment plugin