hexo建站及使用Butterfly主题的Quick Start
- 安装Node.js (含npm),Win系统请从官网 下载,输入以下两条命令确认node与npm是否成果安装
1 | node -v |
- 全局安装Hexo框架
1 | npm install -g hexo-cli |
- 初始化Hexo
1 | mkdir <username>.github.io |
- 配置Butterfly主题
1 | git clone --depth=1 https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly |
修改根目录底下的_config.yml
里的主题属性值theme: butterfly
- 本地预览,默认在
http://localhost:4000
上运行
1 | hexo clean |
本地预览时遇到pug相关报错
extends includes/layout.pug block content include ./includes/mixins/post-ui
这是由于没有安装相关的包,在根目录运行以下指令
1 | npm install hexo-renderer-pug hexo-renderer-stylus --save |
自动化部署的两种方式
A. Hexo 源代码和生成的静态文件在不同两个仓库,Github Actions里无需设置,配置.github/workflows/deploy.yml
即会自动尝试部署,不过本人屡次尝试仍然失败
B. 源代码和 Pages 站点托管在同一个仓库,可参考官方文档,配置.github/workflows/pages.yml
,并且修改Settings > Pages > Source > Github Actions
Hexo部署时按照默认的Jekyll的工作流运行
Error: Logging at level: debug Configuration file: /github/workspace/./_config.yml Theme: butterfly github-pages 228 | Error: The butterfly theme could not be found
先在根目录下添加名为.nojekyll
的零字节空文件,再在_config.yml
里的include属性下添加
1 | include: # <-- put it here (2 spaces indent) |
添加主题自动更新的workflow
在.github/workflows/pages.yml
的配置文件中添加自动更新的工作流(可能会造成部署时间的延长)
1 | - uses: actions/checkout@v4 |
此处由于自动更新主题每次都会重新拉源码,所以对于主题的定制不能继续在themes/butterfly/_config.yml
里了,不然每次更新主题的时候都会把自定义的配置覆盖掉。一般来说Hexo 会先加载你项目根目录下的 _config.yml
,然后再加载根目录下的 _config.butterfly.yml
并覆盖默认值,因此需要在根目录下创建属性与themes/butterfly/_config.yml
完全一致的_config.butterfly.yml
并在这里进行修改。