1
2
3
因为喜欢gitlab,希望通过gitlab pages部署hexo。
我们一般在本地打包好本地文件再放置到github远程仓库上,
然而gitlab部署博客,需要在服务器端完成生成和部署。

环境配置

  • git
  • hexo

操作步骤

  1. 在gitlab新建项目blog
  2. 本地新建hexo项目

    1
    2
    3
    4
    5
    $ cd test  #打开存放项目的目录
    $ hexo init my-blog #下载模版项目
    $ cd my-blog #打开模板项目目录
    $ cnpm install #下载相关依赖的包
    $ cnpm install hexo-deployer-git --save #安装扩展包
  3. 将本地项目添加至远程仓库

    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 #提交至远程仓库
  4. 添加.gitlab-ci.yml部署文件

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    image: 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的时候,都会触发此脚本

  1. 修改项目里_config.yml文件
  1. 再次提交后查看setting里pages,已可以访问网址:https://goddy.gitlab.io/blog/

    参考

Comentários

⬆︎TOP