Hexo - Heuman

Hexo - Heuman

NodeJS / Hexo example with Heuman Theme, on GitLab Pages: https://themes-templates.gitlab.io/hyde/

Hexo Version Node Version Build Status


View site: https://themes-templates.gitlab.io/hexo


Build an Hexo site with GitLab Pages

Settings

Requirements

Hexo is a SSG powered by NodeJS. So we'll need this first:

  • Node JS environment
  • npm
  • git core

Script

We already have a Node image on Docker Library, so we'll require it to run our script on the environment of NodeJS.

This will bring npm and git core with it: image: node:4.2.2

Then we'll need to run:


$ npm install -g hexo-cli
$ npm install
$ hexo generate


We'll set the the npm modules and its dependecies as a cache to speed up our builds:


cache:
  paths: 
    - node_modules/

GitLab-CI

We need to prepare our gitlab-ci.yml configuration file to do as we described previously.

We'll also need a pages job and finally a public folder with our artifacts, afecting only our master branch:


# requiring the environment of NodeJS 4.2.2
image: node:4.2.2

# add 'node_modules' to cache for speeding up builds
cache:
  paths: 
    - node_modules/ # Node modules and dependencies

before_script:
  - npm install -g hexo-cli # Install Hexo itself
  - npm install # Install Hexo modules and dependencies

# the 'pages' job will deploy and build your site to the 'public' path
pages:
  stage: deploy
  script:
    - hexo generate # Hexo generate Static Site
  artifacts:
    paths:
      - public 
  only:
    - master # this job will affect only the 'master' branch

Testing our builds before pushing content to the master branch

What if we want to test our builds in another branch before afecting master? We'll just need to set a test job to do this for us:


image: node:4.2.2

cache:
  paths: 
    - node_modules/ 

before_script:
  - npm install -g hexo-cli 
  - npm install 

# add a job called 'test'
test:
  stage: test
  script:
    - hexo generate
  except:
    - master # the 'test' job will affect all branches expect 'master'

# the 'pages' job will deploy and build your site to the 'public' path
pages:
  stage: deploy
  script:
    - hexo generate
  artifacts:
    paths:
      - public 
  only:
    - master # this job will affect only the 'master' branch

Usage

Note: we assume you have Hexo 3 installed, up and running locally.

  • Fork, clone or download this project
  • Install Hexo Server if you don't have it already: npm install hexo-server --save
  • Configure Hexo _config.yml according to your project
  • Navigate to the project folder (cd path/to/project)
  • Run hexo server

How to change Hexo version?

Modify package.json:


{
  "hexo": {
    "version": "3.2.0"
  }
}

References


Enjoy!