Purpose
Explain how I create this blog with hexo and github.
I wanted to be able to write markdown posts and host them on github.
Prerequisite
- Node.js
- git
- bash
Which blog framework
There is several blog framework. But for our case we need to generate a static blog to commit on our repository (github).
I search on google and find hexo : A fast, simple & powerful blog framework, it is based on Node.js.
Prepare your github repository
Github offers the possibility to have a web site with a domain like “username.github.io”. All information to activate it can be found here Github Page.
Configure github to access it with SSH. Have a look here.
Installing Hexo and configuration
I am not going to write the hexo doc but all information is on the official hexo website.
Once you have installed the package we can start our blog:
1 | $ hexo init <folder> |
Once initialized, here’s what your project folder will look like:
1 | . |
If you create a new post and generate the blog.
1 | hexo new <title> |
A “public” folder will be create with the static web site. This is this folder we want to commit to our github repository.
Create or go to the “public” folder and init the repository.
Create a .gitignore file with the following content:
1 | $ cat .gitignore |
Now we are going to create a Bash script to automatically commit the repository. We want to do fresh commit without old branch. This effectively deletes old articles.
Create “publish.sh” in “public” folder.
1 |
|
Now go back to your hexo folder (cd ..) and create a new bash script “hexo_generate.sh”:
1 |
|
Don’t forget to chmod +x .sh script.
Now you can create articles and automatically publish the blog on github.
That’s it that’s all \o/