Setting up a blog with Hexo using GitHub Pages

Introduction

This articles will show you how to setup a blog with Hexo, a blog framework built with Node.js, and publish it to GitHub.

Setting up Hexo and host it in GitHub

Dependencies

  1. Node.js https://nodejs.org
  2. Git Bash https://git-scm.com or others git tools available online

Install Hexo

  1. Install Hexo, run the following command in git-bash

    1
    2
    cd /your hexo directory/
    npm install hexo-cli -g

    make sure you included the npm directory in your PATH variable

    ;C:\Program Files\nodejs\node_modules\npm
    
  2. Once Hexo is installed, initialize Hexo

    1
    $ hexo init

    following files will be created

    .
    ├── _config.yml
    ├── package.json
    ├── scaffolds
    ├── source
    |   ├── _drafts
    |   └── _posts
    └── themes
    
  3. The site is then ready for deploy

Start Hexo in local environment

  • After installing Hexo, you might want to have a look of the website, you can run the following command

    1
    $ hexo server
  • Server will be started and it can be accessed by using http://localhost:4000

Generate static files

  • Generating static files with the following command
    1
    $ hexo generate

Deploy to GitHub Pages

  1. create a new github repository with name (you github username).github.io

  2. update global setting of hexo _config.yml

    1
    2
    3
    deploy:
    type: git
    repo: link to your github repository
  3. Then run the following command to deploy your Hexo site to gitHub

    1
    $ hexo deploy
  4. you will be able you visit the site with http://(you github username).github.io


Usage

Adding a new post

  1. Run the following command

    1
    $ hexo new post "My First Blog Post"
  2. start blogging by editing the newly created markdown file in <Hexo directory>/source/_posts

  3. regenerate the static files

  4. deploy the changes to remote server if needed

Deleting an existing post

  1. remove the unwanted post in <Hexo directory>/source/_posts

References

  1. Hexo http://hexo.io
  2. GitHub Pages https://pages.github.com