Techumber
Home Blog Work

How & why I migrated from Ghost to Hexo

Published on March 13, 2018

History

When I heard of Ghost(A blogging platform build with Nodejs) for the first time. I have really got excited and started playing with it. I fall in love with it instantly. I felt like this could be a game changes in blogging platform where WordPress has polluted with a lot of unnecessary stuff and too many choices for themes and plugins. Blogger is too difficult to maintain.

I really like Ghost because how we can use markdown to write our blog posts. Since most of my blog posts are about coding it’s a perfect choice.

What happened then. One find day. I see there is a new update. And I updated my docker file accordingly. Everything got messed up there was some problem with the new update. I had to roll back and use the previous version. Even though Ghost just generates static content based on your markdown there are few things to maintain like setup the server, set up the database. Take the backups daily. In my case, I have implemented it on Docker. So I need to do few extra setups. One irritating challenge is Updating. Ghost has updated almost every month. Updating platform every month is bit challenging. Some Reason I didn’t like new Ghost default theme Casper. I really loved old Casper theme. So I decided to move from ghost to some other platform.

Why Hexo?

I use GitHub every day. There are a lot of new features on GitHub. One such is GitHub pages. It’s free totally cool. All you have to do is run one command to publish your blog post. Static site generators are on the rise. There few options like Jekyll, Hexo, Hugo and etc. I think Jekyll is the kind of static site generators but the problem is It’s written in Ruby. I need to setup ruby environment on my machine. Whereas hexo is built with NodeJS which I’m very familiar with. Understanding original source code and fixing few issues by myself is very easy. Most importantly Migrating from Ghost to Hexo is very simple It has all plugins I need. It took me about a day to migrate from Ghost to Hexo. Again that’s because I did some customizations to my theme. One important thing is Hexo is super fast in terms of generating content.

How I did it.

Setup Hexo

Install hexo-cli it’s as simple as installing any node module.

npm install hexo-cli -g

Create your blog

hexo init `your-blog-name`

Install all node modules

cd `your-blog-name`
npm install

Local Server

hexo server

To see your blog running at //localhost:4000

Migrating from the ghost.

Migrating is quite easy.

  1. Sign in to your Ghost then go to Settings > Labs.
  2. Click on Migrate options and Then on Export Content I will download a .json file on your computer.
  3. Install npm install hexo-migrator-ghost --save at the location where you have your hexo blog.
  4. Then run hexo migrate ghost </path/to/your/data.json> file.
  5. Done!

Now, If you inside your source folder you can see all your blog posts imported here.

Casper theme

One of the main reasons I have stated using ghost is the casper theme. Luckily I found the Casper theme ported form ghost to hexo by this guy xzhih. Thanks a million to him otherwise I had to spend time on it.

The theme is exactly what I want. Expect I need to few changes Like Installing Google Analytic, Setup Google Adscence, Setup Prismjs for code syntax, Setup Feedburner subscriptions, Facebook page follow widget, Installing Blog comments, etc.

I’m not gonna write about it here instead I have cloned the theme and updated it here.

Create a new hexo post

To create new blog post run

hexo new post `My Blog Post Title`

Here post is a scaffolding file that you find inside scaffolds folder. You might find another two type draf.md and page.md as well but you can create as many as you want. It’s a quite useful feature.

Deploying it to Github pages.

You will find a _config.yml in your blog root folder. You can control all your blog settings via this yml config file. Now,

Open it and got to deploy section.

deploy:
  type: git
  repo: <repository url>
  branch: [branch]
  message: [message]

For exmaple my config is something like.

deploy:
  type: git
  repo: https://github.com/dimpu/techumber.git
  branch: gh-pages
  message: "blog published"

When you want to publish your blog run

hexo generate
hexo deploy

or

hexo deploy -g

when you run this command it will generate static HTML files based on your markdown in public folder and commits only that folder to gh-pages.

Github pages custom domain

Github pages allow us to have a custom domain. If you don’t know that read through this In short, all you need to have is CNAME file with your domain name in it and then configure your Domain settings at your domain manager server.

One problem is whenever you deploy your code your CNAME will get deleted. To fix this all you have to do is put the CNAME in source folder. Now when every you generate your content it will copied to public folder. Quick simple right?

Final words.

I’m enjoying my new blog platform a lot now. Now don’t have to worry about any difficult technical configurations, docker, taking backups, etc. It’s even better to write the blog post on my VSCode which have this better which now has this better syntax highlighting. When ever you write code related stuff.