How to Create a Blog Using Hexo

Hexo is a fast, simple & powerful blog framework built on Node.js. By using Hexo, I avoided a lot of frustration building a blog while concentrate myself on blog.

Warning: Please go to Hexo to get the most updated guild.

Get Everything Ready

Install Node.js

Node.js is a JavaScript runtime. Hexo is built on Node.js. Node.js can also be used with Express to create more sophisticated websites.

Please download and install Node.js.

Install Git

Git is used to publish the blog. Git is also a very well-known code version control tool. By using Hexo, you don’t need a lot of knowledge of git.

Please download and install Git.

Install Hexo

Install Hexo using npm (Node Package Manager).

1
$ sudo npm install hexo-cli -g

First Hexo Blog

Now I’m going to create my first blog.

1
2
3
$ hexo init blog
$ cd blog
$ npm install

File Structure

There are several important files and folders in the blog folder,

_config.yml

Blog settings can be changed here.

scaffolds

It contains the templates of posts, normally there is no to change it.

source

It contains all original posts

themes

It contains all themes installed, different themes can be switched. Hexo Themes provides plenty of themes to choose.

public

It does not exist at the beginning, but it will appear after your first deployment. It is all auto generated, all its changes will be overwritten in the next deployment.

Setup Pages

Github Pages

Github Pages provides free host for the blog. I already have an account on Github, then I created a repository naming <username>.github.io. In this way Github can recognize its your personal websites.

GitCafe Pages

GitCafe Pages also provides free host for the blog, but it is faster to access in China. I created a repository name <username>. In this way GitCafe can recognize its your personal websites

Binding Custom Domain

If you have a personal domain, it is very easy to direct the domain to the blog by setting a CNAME pointing to <username>.github.io.

In China, DNSPod provides free DNS service and can direct the domain to either GitCafe or Github according to visitor’s IP, which can provide faster access to all visitors.

Change Setting in _config.yml

Deploy segment is in the end on _config.yml.

1
2
3
4
5
deploy:
- type: git
repo: git@github.com:<username>/<username>.github.io.git
- type: git
repo: git@gitcafe.com:<username>/<username>.git

Hexo also supports deployment to Heroku and other places. Detailed instructions can be found here

Basic Hexo Commands

new

1
$ hexo new [layout] "<title>"

Create a new article. layout maybe post, draft, if no layout is provided, Hexo will use the default_layout defined in _config.xml

generate

1
$ hexo generate

Generate static files.

server

1
$ hexo server

Starts a local server, to serve the blog

deploy

1
$ hexo deploy

Deploy the blog.

clean

1
$ hexo clean

Clean up cache file to avoid weird problems.