github&hexo

Setting up a Github Pages blog with Hexo on Mac

Install

Install node.js

1
brew install nodejs

Installing Node.js and NPM is pretty straightforward using Homebrew. Homebrew handles downloading, unpacking and installing Node and NPM on your system. The whole process (after you have XCode and Homebrew installed) should only take you a few minutes.

  • To see if Node is installed, type node -v in iTerm. This should print the version number so you’ll see something like this v7.7.4.
  • To see if NPM is installed, type npm -v in iTerm. This should print the version number so you’ll see something like this 4.1.2.

Install Hexo

1
npm install -g hexo
  • To see if Hexo is installed, type hexo -v in iTerm.

Setup Hexo

Once you’ve got Hexo installed, you can simply run:

1
2
3
$ hexo init username.github.com
$ cd username.github.com
$ npm install hexo-deployer-git --save

Next, we need to configure a couple of things so open up the config file:

1
$ vim _config.yml

Some items you’ll want to immediately change are:

  • title
  • description
  • author
  • url
    To make Github deployments work with hexo deploy you’ll want to make sure that the # Deployment section looks something like:
    1
    2
    3
    4
    5
    6
    # Deployment
    ## Docs: https://hexo.io/docs/deployment.html
    deploy:
    type: git
    repo: https://github.com/username/username.github.io.git
    branch: master

Setup Github

Github provides hosting for static websites via Github Pages. As long as you have an index.html in the root of your repo, Github will serve up the static files for you.

Create a new repository for your blog

You can get this setup by creating the required repository for your new blog, simply create a new repo with the name format as \.github.com, for example: wu-yuanyi.github.com.

Generate some content

Now that everything is assembled in place, it’s time to flesh out the blog. To generate a new post in Hexo simply issue:

1
$ hexo new {postname}

Now you can go ahead and add your content, and then when finished, simply run:

1
2
3
$ hexo clean
$ hexo generate
$ hexo deploy

And your new blog will be live at http://username.github.com