应用Travis CI摆脱Hexo博客换机难
一直以来,用Hexo+Github Page写博客都是一种装逼高端的做法。但是,HEXO写博客是生成静态文件再上传。当需要在别的电脑写博客的时候会比较麻烦。所以,现在使用Travis CI来解决这一问题。
获取Personal Access Token
1.进入设置
2.点击Personal Access Token
3.点击右上角的Generate new token
4.设置Token description,选择权限
5.点击Generate token
6.复制生成的Personal access tokens(注意:token只会在刚刚创建完成后显示一次,关闭页面后再打开不再显示)
配置Travis CI
1.用Github账号登陆Travis CI
2.点击左上角的“+”
3.点击博客源码仓库前面的滑块
![open]7.JPG)
4.点击滑块旁边的设置
5.点击Build only if .travis.yml is present
前面的滑块
6.在Environment Variables
添加你的Personal access tokens
7.点击add
配置仓库文件
1.在源码仓库创建.travis.yml
2.在文件内写入信息(以下供参考,更详细请参考Travis CI文档 )
language: node_js
node_js: stable
# S: Build Lifecycle
install:
- npm install
#before_script:
# - npm install -g gulp
before_install:
- export TZ='Asia/Shanghai' # 设置时区
- npm install -g hexo
- npm install -g hexo-cli
script:
- hexo clean
- hexo g
after_script:
- cd ./public
- git init
- git config user.name "你的昵称"
- git config user.email "你的邮箱"
- git add .
- git commit -m "Update docs"
- git push --force --quiet "https://${GH_TOKEN}@${GH_REF}" master:master
# E: Build LifeCycle
branches:
only:
- master
env:
global:
- GH_REF: github.com/*******/********.github.io.git(Github Page仓库)
最后
1.写一篇新文章,push源码到github
2.在Travis CI就可以看到正在构建了(黄色)
3.build passing之后(绿色)就可以在博客网页看到新文章了。
应用Travis CI摆脱Hexo博客换机难
https://blog.loststar.tech/posts/d9cdb463/