0%

Building a Hexo Blog with GitHub Pages

Install Hexo

1
2
npm install -g hexo-cli
export PATH=~/.npm-global/lib/node_modules/hexo/bin:$PATH

Create root Hexo folder

1
2
3
mkdir hexo_dir
cd hexo_dir
hexo init

Configure Git Repo

Create a github repo <username>.github.io and edit _config.yml:

1
url: <username>.github.io

Download a theme

1
2
3
# 2 alternative themes that I find useful
git clone https://github.com/cofess/hexo-theme-pure.git themes/pure
git clone https://github.com/yscoder/hexo-theme-indigo themes/indigo

Then edit the theme property in _config.yml and setup theme-specific properties in themes/<theme>/_config.yml

Preview Locally

1
hexo serve

Publish

For GitHub Pages, we need to install hexo-deployer-git plugin and config the deploy property in _config.yml. Note that personal pages must be pushed to the master branch (not gh-pages!)

1
2
3
4
deploy:
type: git
repo: git@github.com:<username>/<username>.github.io.git
branch: master

Then publish to GitHub:

1
2
3
hexo clean
hexo generate
hexo deploy

Comment

Most themes have built-in support for comment systems. I personally find gitalk to be the most easy-to-use one. You just need to apply for a new Git OAuth application and fill in necessary info in themes/<theme>/_config.yml:

1
2
3
4
5
6
gitalk: 
owner: <username>
admin: <username>
repo: <username>.github.io
ClientID: <ClientID>
ClientSecret: <ClientSecret>

Note that the comment system should be working even in a local review.

Tags, Categories, About

1
2
3
hexo new page tags
hexo new page categories
hexo new page about

In the created .md files, edit the type attribute:

1
2
3
4
5
6
---
title: Tags
date: 2020-06-24 23:10:07
layout: tags
type: tags
---