0. Assume you have already installed Node.js and git.
1. Install Hexo CLI globally.
1 | npm install -g hexo-cli |
2. Use Hexo CLI to create your project and initialize it.
1 | hexo init <project-name> |
3. Setup version control for your project.
1 | git init |
4. (Optional) Replace the default theme.
Follow the instructions here: How to Change Hexo Themes.
This blog is using NexT theme if you’re interested.
Don’t forget to commit it:
1 | git add _config.yml |
5. Auto-Deploy to GitHub Pages with Travis CI.
Preparation
Create an empty repo on GitHub named blog
.
Add Travis CI to GitHub in the Marketplace, and add the blog
repository in Travis CI.
Config Access Token
Go to Personal access tokens page on GitHub,
Generate a new token with repo scopes. Copy that generated token.
Open Travis CI, add your blog
repo and then go to Settings.
Add an Environment Variables with GH_TOKEN
as name and paste that token as value. Save it.
Add Config File
Add a .travis.yml
file to your project with the following content:
.travis.yml (Click to open)
1 | sudo: false |
Commit it:
1 | git add .travis.yml |
Push your project.
1 | git remote add origin https://github.com/<your-username>/blog.git |
Re-Check
Open the repo’s Settings on GitHub, navigate to GitHub Pages section.
Make sure gh-pages branch
is selected as the Source option.
Check the webpage at your-username.github.io/blog !
From now on, you can even add or edit posts on GitHub directly!
Travis CI will detect the updates and rebuild your page for you!
Happy Blogging!