Setting up a blog using Hexo

  1. 1. Step 1: A GitHub repository for the website
  2. 2. Step 2: Setup the Node.js environment
  3. 3. Step 3: Setup the website
    1. 3.1. Initialize local folder
    2. 3.2. Basic configurations for the website
    3. 3.3. Editing the website locally
  4. 4. Step 4: Deployment on GitHub
  5. 5. Step 5: Version control (Optional)
  6. 6. Other useful links:
  7. 7. References

This applies to Windows 10 and Ubuntu 12.04.

Step 1: A GitHub repository for the website

On GitHub, create a repository

1
<yourname>.github.io

Make sure the .gitignore type is Node.

Step 2: Setup the Node.js environment

Install Node.js. Then install necessary component:

1
npm install -g hexo-cli

Step 3: Setup the website

Initialize local folder

Then, in a given folder, initialize the website

1
hexo init [folder]

In this folder, install a module for commiting to GitHub. Be sure to add --save so that the module is installed inside this folder and can be used by the server.

1
npm install hexo-deployer-git --save

Basic configurations for the website

Modify the configuration file

  1. The site section
  2. The deployment section, e.g.
    1
    2
    3
    4
    deploy:
    type: git
    repo: https://github.com/<yourname>/<yourname>.github.io.git
    branch: master

An alternative for repo is

1
repo: git@github.com:<yourname>/<yourname>.github.io.git

In my case, the https works for Win10, while the git version works for Ubuntu.

Editing the website locally

To generate and check the website locally

1
2
3
hexo clean
hexo generate
hexo server

And the website is hosted on

1
https://localhost:4000

More info:

  1. Generating
  2. Server

To add a new article

1
hexo new [title]

Then modify the corresponding .md file in source/_posts. More info: Writing

Step 4: Deployment on GitHub

To deploy

1
hexo deploy

More info: Deployment

Step 5: Version control (Optional)

Deployment only pushes the generated contents (the public folder) to GitHub, not the source files. To work on multiple machines, it is beneficial to create an online repository. In this repository, some folders do not have to be tracked:

  1. public and db.json: Generated automatically every time before deployment.
  2. node_modules: Quite large, and not all are necessary. One can repeat Step 3 to create these modules.
  3. .deploy_git: Not essential. It can be generated every time hexo deploys the website. An issue might be the slowness due to a large website.
  1. Hexo
  2. documentation
  3. troubleshooting and GitHub

References

  1. zhangslob.github