Reboot – Migrating from Tumblr to Kirby

For quite a while, I've been writing all my post drafts as markdown formatted text files in a drafts folder on my computer. The first version of Foolproof UI was on Tumblr. Tumblr was nice, but with Kirby, the step of copying the draft through a web interface got eliminated. Kirby just reads text files from folders.

Here's roughly how I migrated my posts from Tumblr, in case anyone wants to do the same.

First off, I got my posts backed up by getting them all as JSON through the Tumblr API. I then saved the JSON in a file as archive.js.

Then I wrote two html files with inline scripts that used the good old document.writeln(). One to give me the shell commands that would write a folder and file structure that mirrored the one I had on Tumblr and another to convert the JSON posts to Kirby posts into one big file. I opted to just copy and paste each post from the big file into its own file since there weren't that many posts.

The folder structure script was rather simple:

archive = archive.concat(archive1, archive2, archive3, archive4);

$.each(archive, function(i, val) {

  var post = archive[i];

  document.writeln('mkdir ' + post.id);
  document.writeln('cd ' + post.id);
  document.writeln('mkdir ' + post.slug);
  document.writeln('cd ' + post.slug);
  document.writeln('touch ' + post.slug + '.txt');
  document.writeln('mate ' + post.slug + '.txt'); //Open the created file in Textmate for pasting the contents in
  document.writeln('cd ../..');
  document.writeln('');

});

The output for a single post:

mkdir 33300755388
cd 33300755388
mkdir colour-management-and-ui-design
cd colour-management-and-ui-design
touch colour-management-and-ui-design.txt
mate colour-management-and-ui-design.txt
cd ../..

I copied the output to the terminal and step one was done. I had a bunch of named text files open in Textmate. The post conversion script was a bit lenghtier, but still very simple. Basically it just iterated over each post object in the posts array (in the posts JSON file) and wrote a line of text for each property. It began like so:

$.each(archive, function(i, val) {
  var post = archive[i];
  document.writeln('Title: ' + post.title);
  document.writeln('----');
  document.writeln('Text: ' + post.body);
}

Download the full conversion script. There's iteration over tags, date conversion and handling of different types of posts. (No video posts though.)

From there on I copied the output text of the second script into that big file of Kirby posts and copied each post to its corresponding file that was already opened in Textmate by the first script. Some manual work there, but it was enough to get the job done.