Migrating from ASP.NET to Ghost / node.js

I just made the transition from my custom-built ASP.NET blog to Ghost. Ghost is a free, open-source blogging platform (and it is the first 3rd party system I've liked. Yeah. It's good.). During this transition, I ran into a couple of problems, namely:

  1. How do prepend `/blog` to the blog posts, as was the standard on my ASP.NET blog?
  2. How to 301 redirect the .aspx pages to their Ghost equivalent?
  3. How to re-create my JSON feeds?

Please note that the über-hacky changes I made require minor updates to the Ghost framework, and changes like these would get overwritten if you update Ghost. BUT, it got the job done. So let's start:

Change the url to start with /blog

This was one of the easier changes (side note: I used postgres as the DBM). Go to the database, and then the settings table. Update the permalinks key from /:slug/ to /blog/:slug/. Done!

301 redirect .aspx pages

Bear with me. I couldn't find a great way to do this and I really wanted to get the new blog up. I only had two pages in my previous site that ended in .aspx, so I took a straightforward route -- I modified the 404 route. This is the error404 function in core > server > errors > index.js. In this case, I wanted to redirect /examples/modal-calendar.aspx to /fullcalendar-jquery-ui-modal/:

 error404: function (req, res, next) {
    var message = res.isAdmin && req.user ? 'No Ghost Found' : 'Page Not Found';

    //crappy hack. Catch 404 and reroute
    if (req.url.indexOf("/examples/modal-calendar.aspx") > -1) {
        res.writeHead(301, {"Location": "http://www.mikesmithdev.com/fullcalendar-jquery-ui-modal/"});
    //rest of code

Glorious. Now what about those feeds? It was the same fix. I was going for a quick and dirty solution. I didn't try to make a beautiful update to the Ghost code to handle JSON feeds gracefully.

Creating JSON feeds

Again, I updated that same 404 function as above:

error404: function (req, res, next) {
    //other code above
    if (req.url.indexOf("/hackyjson/cal") > -1) {
        var events = [];
        //magically build my JSON feed to run the calendar demos and then...
        res.setHeader('Content-Type', 'application/json');

Nasty, yeah. But it worked. And now I have a shiney new blog.