Github Actions服务的免费用户支持2000分钟/月的使用额度,对于个人用户足够了
部署完成后,在hexo-build/source/_posts 新增对应的文件后,即会自动构建hexo博客,然后自动推送更新到github pages服务上。
- themes目录,可以把自己喜欢的主题放在这个themes目录下,然后在_config.yml配置使用的主题
- sources目录,主要存储markdown文档、以及一些静态文件
clone本项目代码,并push到你的私有git仓库,当然你也可以图省事直接fork。一般博客markdown文件,建议还是私有库好点,毕竟还有一些草稿之类的目录。
最终拿到仓库地址如下所示:
https://github.com/h1ac0k/hexo-builder
使用Github Access Token来访问github pages所在的仓库,token生成后按下面的结构修改_config.yml文件上部署部分的代码。
注意token的作用范围设定为最小的(只要可以访问github pages对应的仓库权限即可),网络上有的做法是直接将SSH Key丢到自动化构建里头,这是非常不安全的。
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo: https://[这里填写你的github access token]@github.com/[github 用户名]/[[github 用户名]].github.io.git
branch: master
message: "{{ now('YYYY-MM-DD HH:mm:ss') }}"
# 构建本地镜像
docker build -t hexo .
# 生成静态文件
docker run -p 4000:4000 -v /Users/apple/Documents/dev/hexo-builder/source:/var/www/hexo-builder/source/ -v /Users/apple/Documents/dev/hexo-builder/themes:/var/www/hexo-builder/themes/ --rm -it hexo hexo generate
# 开启预览服务
docker run -p 4000:4000 -v /Users/apple/Documents/dev/hexo-builder/source:/var/www/hexo-builder/source/ -v /Users/apple/Documents/dev/hexo-builder/themes:/var/www/hexo-builder/themes/ --rm -it hexo hexo server
文档可能有些地方可能说得不明白,可以直接提issue。