可搜索,可注册,可登录,致敬逗比大佬!尽在救援版逗比根据地 dbgjd.com
投稿文章 | 广告合作 | Telegram 群组 / 公告频道 / 使用教程

使用 travis-ci 自动化构建博客

News johng1969 540℃ 0评论

之前的 hexo 博客我都是在电脑上进行生成然后 push 上 github repo,现在感觉有些麻烦 就是懒 所以就想着能不能用 travis-ci 自动化构建博客。

准备

创建分支

我采用的方法是在 github 仓库上创建两个分支,mastersource,分别存放生成的网站文件以及源文件。

编写 travis 配置文件

文件内容如下:

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
language: node_js
node_js: stable
branches:
only:
- source
cache:
apt: true
yarn: true
directories:
- node_modules
before_install:
- git config --global user.name "johnpoint"
- git config --global user.email "[email protected]"
- curl -o- -L https://yarnpkg.com/install.sh | bash
- export PATH=$HOME/.yarn/bin:$PATH
- npm install -g hexo-cli
install:
- yarn
script:
- npm install hexo-renderer-pug --save
- npm install hexo-renderer-sass --save
- npm install hexo-generator-feed --save
- hexo clean
- hexo generate
after_success:
- mkdir push
- cd ./push
- git clone https://github.com/johnpoint/johnpoint.github.io .
- rm * -rf
- cp ../public/* . -r
- git add --all .
- git commit -m "Travis CI Auto Builder"
- git push --quiet https://[email protected]/johnpoint/johnpoint.github.io
master

配置 github 密钥

因为之前我是打开了 github 的双因素认证,所以 push 不能使用原来的 github 用户名 + 密码的方式进行身份认证了。

使用 travis-ci 自动化构建博客

在上图的地方加入 name 为 REPO_TOKEN,value 为 Personal access tokens

等待开始构建

一般来说要做的工作就已经完成了,只需要静静的等待 travis-ci 的构建完成,这篇文章就是通过自动构建生成的

使用 travis-ci 自动化构建博客

转载请注明:逗比根据地 » 使用 travis-ci 自动化构建博客

喜欢 (0)
发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址