How to setup blog?
Kexin Tang

Github

Just create a new repo, and the repo’s name follows rule “username.github.io”.


Node.js & Hexo

Install

Just donwload Node.js from offical website (maybe you also need npm :)). For Mac user, the simplest way is run command:

1
brew install node

For Hexo, we just need to run

1
npm install hexo-cli -g

After installation, use commands to validate:

1
2
3
node -v
npm -v
hexo -v

Init

If everything is OK, run following commands:

1
2
3
mkdir blog && cd blog
hexo init # init the folder as blog repo
npm install # install necessary node_modules

Then you will find a file named blog/_config.yml, add these info in last rows:

1
2
3
4
5
6
# Deployment
## Docs: https://hexo.io/docs/one-command-deployment
deploy:
type: git
repository: <your github repo>
branch: master

Deploy

You can add a new plug-in npm i hexo-deployer-git so that we can post blogs to git via hexo.

1
2
3
4
hexo new post "this is post name"
hexo g # generate
hexo s # can view changes in localhost
hexo d # deploy to github

:money:

Actually this step is optional, cause u can use “username.github.io” to browse your blog. However, if you want a fancy URI (and you are rich), you can follow the step.

You should buy a web URI, I got one from GoDaddy.

After you got one, let’s say it’s “myfancyblog.com”, you should set the DNS so that when other people enter “myfancyblog.com” in browser, it can re-direct to “username.github.io”.

1
2
Other people                  Your github repo
"myfancyblog.com" - DNS -> "username.github.io"

In DNS Management page, you should set two more DNS Records.

Type Name Data
A @ IP Address For username.github.io
CNAME www username.github.io

The first one re-directs “myfancyblog.com” to “username.github.io”‘s IP, the second re-directs “www.myfancyblog.com“ to “username.github.io”.

Then, you should go back to your blog repo, in blog/source create a new file CNAME, then put “myfancyblog.com” in this file. hexo g && hexo d. You will see github.com will have a new CNAME file, and you can check “Setting -> Pages”, it should have “myfancyblog.com” in “Custom domain” field.


Tips

If you are curious about “why I changed some settings but the web page seems no change”, :(, well, remember to clear the browser cache.