How I migrated from Ghost to Hexo

A little bit of history

When I discovered Ghost 3 years ago, my initial enthusiasm, because it was bringing a wave of fresh air in this world polluted by WordPress and sites written in PHP, rapidly declined and now I’m going to briefly explain why.

Immediately I noticed that was too cumbersome working with Ghost, even if it’s just a Static Site Generator, you have to setup a nodeJS hosting with a DB, just to have some static page generation capability.

If this is not enough you have to face the lack of features, speaking of 2 years ago, it was in beta ( exactly as today, I just checked is still version 0.9.0 ).

So I left the blog to itself, themes were too complex to handle, the pleasure of writing flew away and I was too busy to take care of this little baby full of issues.

What happened then

Some days ago, while I was enjoying the holidays drinking Mojitos after lunch, the blog came back to my mind. I thought that in this spare time I could check if the Ghost platform was evolved to some point and if I could maybe start again my adventure with a blog.

Ghost Blog on Docker

After some Googling I started to setup the new version of Ghost 0.9.0, to give it a try, using Docker ( i didn’t want to use OpenShift V2.0 to handle my application anymore ).

After some customization and creating the docker-compose.yml file I saw there were some issues with the Ghost Dockerfile not working properly. Before starting to mess again with it I choose to look around for other solutions

Googling around brought me to many posts of people tired of Ghost, for all the reasons I described above and moving to other platforms one of those being Hexo.

What is Hexo

Hexo, like his big brother Jekyll ( written in Ruby ), is a real Static Site Generator that uses NodeJS to easy the pain of generating your content and then leaving you with only a public folder full of html, css, js and images to upload to any hosting you prefer ( like Github pages ).

Hexo + Github pages

Github pages + Hexo

With Github pages and Hexo you get the cake and eat it too! You have:

  • an easy to use and powerful static site generator that works well with git
  • free hosting that requires only a commit to update your site

Getting started

This is how you can get started with Hexo

Requirements:

  • NVM or NodeJS + NPM
  • GIT

Install hexo-cli and setup your blog

First of all, we need to install the hexo-cli to help us setup and handle the blog

1
npm install hexo-cli -g

Then move where you want to keep your blog folder and run

1
hexo init `your_blog_name`

Now we must install dependencies

1
2
cd `your_blog_name`
npm install

And we have finished!

Run Hexo Server and create a post

To start a local server and see our blog before going online we need to launch Hexo server, it takes care of everything you need! From inside your blog folder run

1
hexo server

To create a post open another terminal and, always from inside your blog folder, run

1
hexo new post `My Blog Post Title`

Publish on Github pages

To publish our site Hexo offers a deploy command that can use many plugins, if you stick with Github pages you need only the git one that’s already included.

First of all, we must create a repository on Github and name it like SharpEdgeMarshall.github.io

Then paste the repository url in our _config.yml

1
2
3
4
5
6
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repository: [email protected]:SharpEdgeMarshall/sharpedgemarshall.github.io.git
branch: master

From now on we can just run

1
2
hexo generate
hexo deploy

or just

1
hexo deploy -g

To get our generated site committed on Github and published on Github pages

One important thing to note is that hexo deploy commit only the content of the /public folder, the one that gets generated. You still have to keep your source on git ( maybe in a private repo ).

Here is a simple .gitignore to help you setup the repository.

1
2
3
4
5
6
.DS_Store
node_modules/
*.log
db.json
public/
.deploy*/