Introduction
Github pages
Github pages is a github service that can host personal or project web pages directly from a github repository. This is ideal place to host my blog site because it is fast, and I will have a
Hexo
The most popular blog framework that supports github pages is Jekyll It seems, because it is officially recommended by github. But I found another framework Hexo, which compared to Jekyll, is similar but much easier to use, I only need to know 4 commands,
1 | hexo n # new post |
After I checked out some Hexo built blog sites, I decied to go with Hexo. Hexo is wirtten in node.js, and it supports a lot powerfull plugins and has cool themes.
Install Hexo
Follow Hexo doc
Set up Github Pages
Create github pages repository on github.com, the repository name is vmnet8.github.io where vmnet8 is my github account.
Install and configure Git which Hexo requires
Install git. I am coding and will be blogging on my Ubuntu Linux, to use Hexo to deploy my blog site to github pages, I need to install and configure git first. Install:
1 | $ sudo apt install git |
Configure git with github
1 | $ git config --global user.name "Anna X" |
Add my ssh public key to github. I will have Hexo deploy to github pages over ssh without asking username and password.
Install Node.js
Follow node.js doc
Install node.js using package manager - APT
1 | $ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash - |
As of 12/21/2017, node.js version is v8.9.3
1 | $ node -v |
Install hexo-cli
Follow Hexo doc
1 | sudo npm install -g hexo-cli |
As of 12/21/2017, hexo version 3.4.3
1 | $ hexo version |
Build my blog using Hexo
Initialize my blog folder
Follow Hexo setup doc, I use “vmnet8.github.io” as my blog folder.
1 | $ hexo init vmnet8.github.io |
Basic blog site configuration
Edit blog configuration file _config.yml in blog folder.
1 | # Site |
Note that when editing _config.yml file which is YAML format file, for key-value pairs format like “key: value”, there should be a space after “:”, same for sequence item, there should be a space after “-“
Create blog post using Hexo
Create my first blog post
1 | $ hexo new "1st blog" |
Edit the blog post file 1st-blog.md
1 | $ vi source/_post/1st-blog.md |
The blog post .md file is markdown format file with a header called “Front matter”
1 | --- |
The front matter is YAML format .
The blog content below front matter is markdown format which is a lightweight markup language with plain text formatting syntax. It is designed so that it can be converted to HTML.
When creating blog folder using “hexo init”, a sample blog post source/_posts/hello-world.md will be created automatically, you can cat it for reference.
Test blog post
Run “hexo g” to generate the static html files and “hexo server” to start http service on port 4000 for blog access.
1 | $ hexo g |
Then go to http://localhost:4000/ in browser.
Notes:
- Every time you run hexo command, you current dir should be the hexo blog folder.
- Note: every time you make change to the configuration file or any page or post, you need to do “hexo g” to generate the new static html files. If something wrong happens due to wrong syntax in yml configuration file or md markdown file, you may need to do “hexo clean” and then “hexo g” to re-generate all blog html files.
Deploy blog to github pages
Follow Hexo deployment doc
Install git hexo deployer plugin.
1 | npm install hexo-deployer-git --save |
Note: When you install hexo module by “npm install
Configure deployment to higthub, edit blog configuration file _config.yml in blog folder
1 | deploy: |
I use ssh instead of https for my github pages repository access for Hexo, so I won’t need to enter username/password for deployment to github.
Deploy to github pages
1 | $ hexo d |
Then go to my github pages https://vmnet8.github.io in browser.