Gitlab上搭建Hexo博客

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

1. 安装hexo

参考Hexo官方文档安装依赖的Node.js, git, hexo.


2. 配置Gitlab

参考文档:
利用gitlab pages和hexo搭建一个个人博客
Hosting on GitLab.com with GitLab Pages
与Github的gitpage不同的是, 在Gitlab上使用hexo搭建博客,不需要在本地生成静态文件之后push到Github.
而是只需要在本地编辑markdown文件, 推送到Github之后, 在Github运行pipeline生成和部署静态文件.这样极大方便了博客的迁移和管理.

  • 在Gitlab上创建一个project, 名称必须为yourname.gitlab.io
  • 在本地创建一个空文件夹, 利用hexo命令初始化, 关联到远程的gitlab项目

    1
    2
    3
    $ hexo init

    $ git remote add origin https://gitlab.com/yourname/yourname.gitlab.io.git
  • 重点: 创建一个.gitlab-ci.yml配置文件

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    image: node:8.11.2

    pages:
    cache:
    paths:
    - node_modules/

    script:
    - npm install hexo-cli -g
    - npm install
    - hexo deploy
    artifacts:
    paths:
    - public
    only:
    - master
  • 编辑markdown文件, 推送到远程, pipeline跑过了之后就可以看到博客了https://yourname.gitlab.io.git


3. Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment