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 | node -v |
Init
If everything is OK, run following commands:
1 | mkdir blog && cd blog |
Then you will find a file named blog/_config.yml, add these info in last rows:
1 | # Deployment |
Deploy
You can add a new plug-in npm i hexo-deployer-git so that we can post blogs to git via hexo.
1 | hexo new post "this is post name" |
: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 | Other people Your github repo |
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.