RSS feed

From Ghost To Nanoc

I completed my blog migration from Ghost to nanoc.

About 2 years ago I did setup a blog on blog.as.it using Ghost. It’s UI was very minimal and I liked the default theme (Casper) a lot.

However, I kept nanoc for my main website, until I decided to give Hakyll a try. It’s not that nanoc didn’t satisfy me at that time, but that I was fascinated by Haskell - I’m still fascinated by Haskell, but I’ve no much time to play with it, while I play with Ruby more often.

Someday ago I thought it was time to merge my website and my blog; both could be handled by a static site generator and since I’m fluent in Ruby more then Haskell, I went for nanoc again.

The migration has not been hard because one of the main features of Ghost is that you write your post using Markdown, then I wrote this shell script to migrate my posts from Ghost to a “nanoc compatible format” like:

---
kind: article
created_at: 2015-10-06
title: My Ghost Post
tags: ['example']
---
This is a post in **Ghost**!

With that script my posts were split and ready in the content folder to be built by nanoc. Nothing more to do! Well, in truth I had to fix the path to the linked images manually…

The second step was to put some redirect to allow the old links around the web to continue to work, specifically the Ghost pattern was http://blog.as.it/my-ghost-post/ while in nanoc I went for http://www.andreascarpino.it/posts/my-ghost-post.html. I fixed this in my blog nginx configuration:

location = / {
  rewrite ^ $scheme://www.andreascarpino.it permanent;
}

location / {
  rewrite ^(.*) $scheme://www.andreascarpino.it/posts$request_uri permanent;
}

location = /rss/ {
  rewrite ^ $scheme://www.andreascarpino.it/feed.xml permanent;
}

While in the website nginx configuration I put:

location /posts/ {
  root   /srv/http/website;
  if ($request_filename ~* ^.+.html$) {
    break;
  }
  if ($request_uri ~* ^.+/$) {
    rewrite ^/(.*)/$ /$1.html permanent;
  }
}

And that’s!

Hope this helps someone that plans to do the same migration. If you are interested at looking at my nanoc setup, the configuration is here.

Tags: howtos

By Andrea Scarpino on 2015-10-06