Create your blog with Hexo on GitHub Pages

  1. prerequisites
  2. Hexo
  3. GitHub Pages

prerequisites

First of all, make sure you have Node.js and Git installed on your machine.

Hexo

Run the following commands in your favorite terminal:

1
2
3
4
5
npm install hexo-cli -g
hexo init blog
cd blog
npm install
hexo server

It might takes a few minutes to finish, If everything goes smoothly, you have successfully installed Hexo. Now visit http://localhost:4000 in your browser, you can see your hexo blog is running:

To create a new post, run the following in your terminal:

1
$ hexo new "My New Post"

Refresh you blog page, you will notice the new post has been displayed.

GitHub Pages

There are two ways of deploying to GitHub Pages.

  • use GitHub Actions - It works in both public and private repository.
  • One-command deployment - If you prefer not to upload your source folder to GitHub.

I would prefer the second solution because I don’t want to upload my source folder to a public GitHub repository.

  1. Install hexo-deployer-git.
    1
    npm install hexo-deployer-git --save
  2. Add the following configurations to _config.yml (remove existing lines if any)
    1
    2
    3
    4
    5
    deploy:
    type: git
    repo: https://github.com/<username>/<project>
    # example, https://github.com/hexojs/hexojs.github.io
    branch: gh-pages
  3. Run hexo clean && hexo deploy
  4. Check the webpage at username.github.io.