使用gitlab部署hexo
序
1 | 因为喜欢gitlab,希望通过gitlab pages部署hexo。 |
环境配置
- git
- hexo
操作步骤
- 在gitlab新建项目blog
本地新建hexo项目
1
2
3
4
5$ cd test #打开存放项目的目录
$ hexo init my-blog #下载模版项目
$ cd my-blog #打开模板项目目录
$ cnpm install #下载相关依赖的包
$ cnpm install hexo-deployer-git --save #安装扩展包将本地项目添加至远程仓库
1
2
3
4
5
6$ cd my-blog #打开项目目录
$ git init #设置项目目录为git仓库
$ git remote add origin git@gitlab.com:Goddy/blog.git #连接远程仓库
$ git add . #添加文件
$ git commit -m 'msg' #添加注释并合并至本地git仓库
$ git push #提交至远程仓库添加.gitlab-ci.yml部署文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16image: node:4.2.2
pages:
cache:
paths:
- node_modules/
script:
- npm install hexo-cli -g
- npm install
- hexo deploy
artifacts:
paths:
- public
only:
- master
注:gitlab-ci全称是gitlab continuous integration的意思,就是持续集成。每次在我们push到gitlab的时候,都会触发此脚本
- 修改项目里_config.yml文件
- url设置为:https://goddy.gitlab.io/blog
- root设置为:/blog/
- 再次提交后查看setting里pages,已可以访问网址:https://goddy.gitlab.io/blog/
参考