Hexo博客部署记录
Hexo是一个基于Node.js的静态网站生成器,主要用于创建博客和文档网站。
一、安装环境
- nodejs官网
https://nodejs.org/zh-cn
- git官网
https://git-scm.com/
- 验证
1 2 3
| node -v npm -v git --version
|
二、安装Hexo
- 全局安装Hexo
- 初始化站点
1 2
| hexo init wiki.bravexist.cn cd wiki.bravexist.cn
|
- 安装依赖
三、生成静态文件并启动本地服务器
- 清理旧文件
- 生成静态文件,可简写
hexo g
- 启动预览,默认 http://localhost:4000,,可简写
hexo s
四、写文章
Hexo 默认文章都在 source/_posts/ 下。
创建一篇文章:
1
| hexo new post "Hexo博客部署记录"
|
五、推送到Github
新建一个仓库
1
| https://github.com/username/blog.example.com.git
|
1 2 3 4 5 6 7 8
| git config --global user.name "YourName" git config --global user.email "YourEmail@example.com" git init git add . git commit -m "first commit" git branch -M main git remote add origin https://github.com/username/my-blog.git git push -u origin main
|
六、修改主题
这里使用 Butterfly
- 安装主题
1
| git submodule add -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly
|
- 修改配置文件
_config.yml
- 安装插件
1
| pnpm install hexo-renderer-pug hexo-renderer-stylus --save
|
- 创建主题配置文件,复制
_config.yml 的内容
七、手动bat上传github
push.bat
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| @echo off :: 设置编码为 UTF-8,防止中文乱码 chcp 65001 >nul title Auto Git Push Tool color 0A
echo ======================================================= echo 正在准备推送到 GitHub ... echo ======================================================= echo.
:: 1. 查看当前状态 echo [1/3] 查看变更状态 (git status) git status echo.
:: 2. 添加所有文件 echo [2/3] 添加文件到暂存区 (git add .) git add . echo.
:: 3. 提交更改 :: 获取用户输入,如果直接回车,则使用默认时间戳 set "msg=" set /p "msg=请输入 Commit 信息 (直接回车默认使用当前时间): "
if "%msg%"=="" ( set "msg=Auto update: %date% %time%" )
echo. echo [3/3] 正在提交并推送... echo Commit 信息: "%msg%" echo.
git commit -m "%msg%" echo.
:: 4. 推送到远程仓库 echo 正在推送到 GitHub,请稍候... git push
echo. echo ======================================================= if %errorlevel% == 0 ( echo [SUCCESS] 推送成功! ) else ( echo [ERROR] 推送失败,请检查上方报错信息。 color 0C ) echo =======================================================
:: 暂停,让你看一眼结果,按任意键关闭 pause
|
八、部署到Edgeone
Edgeone
选择GitHub仓库,选择Hexo构建,绑定自定义域名。
九、参考文献