MovableType to Blosxom conversion

I decided to convert my entire weblog to Blosxom. The constant problems I have with MovableType finally beat my brain into realizing that a better solution must be out there. And, since Inklog isn’t exactly ready yet, I figured a few hours of converting now, will save me lots of headache in the future.

Unfortunately, the one thing I LOVE about MovableType is no where to be found in Blosxom: templates. Sure, you can alter the look of your Blosxom based website, but its template engine is nothing more than the most amatuer use of search-and-replace. After the conversion was finished and I started altering the Blosxom templates, I realized this.

Everything is ready to go, but I haven’t made it live yet. I’m not sure if the loss of this functionality is worth everthing that I gain from using Blosxom. If Blosxom supported multiple categories per entry, I think I’d willing to overlook everything else. But, add that to the template issue and I’m uncertain if it is a step forward, or a step back.

None the less, I figure there are other people out there who might want to convert from MovableType to Blosxom as well, so I decided to outline the instructions here.

First, two new Individual Archive templates need to be added to MovableType. Label the first one “Blosxom Individual Template” and fill it with the following:

creation_timestamp: <MTEntryDate format="%Y%m%d%H%M%S">
categories: <MTEntryCategories glue=","><MTCategoryLabel></MTEntryCategories>

<!-- more -->

Make another template called “Blosxom Writeback Template” and fill it with this:

name: <MTCommentAuthor>
url: <MTCommentUrl>
url: <MTPingURL>
title: <MTPingTitle>
blog_name: <MTPingBlogName>

Go into “Blog Config” and add two new Individual Archive templates. For the “Archive File Template” field, prefix the field with /blos/ for the “Blosxom Indvidual template” and with /blos_wb/ for the “Blosxom Writeback Template”. You can make the rest of the URL look however you’d like. I decided that, in Blosxom, I wanted my entries divided by primary category. For this reason, I decided to make mine look like this: blos/<MTEntryCategory dirify="1">/<MTEntryID>_<MTEntryTitle dirify="1">.txt. Again, you can do whatever you’d like, as long as it ends in .txt starts with something unique to your MovableType blog (like /blos/) and is certain to produce unique names for each entry. Additionally, the names of the directories leading to the entry can’t start with a number, or Blosxom will freak out. Make the “Archive File Template” be the same for the “Blosxom Writeback Template”, just change the prefix.

Rebuild your entries. All of them. If, like me, your webserver decided to choke when you tell it to do this, and you happen to have shell access to your server, try running the following script instead of rebuilding over the web:



# Settings:

$MT_DIR = '/home/revjim/www/mt';
$BLOG_ID = 2;



use strict;
use lib "$MT_DIR/lib";
use lib "$MT_DIR/extlib";
use Data::Dumper;
use MT;
use MT::Entry;
use MT::Blog;
use MT::Placement;
use MT::Category;
use MT::ConfigMgr;

my $MT = MT->new( Config => "$MT_DIR/mt.cfg" ) or die MT->errstr;
$MT->rebuild( BlogID => $BLOG_ID );

Take a nap, read a good book, or get some excercize while you wait. It could be a while.

When it’s all over, you should have two new directories in the same place that your regular MovableType archives go. These will be moved into the Blosxom data directory when it’s ready.

Install Blosxom according to its instructions. If you can’t figure this out, then you’ll have a hard time doing any of the following steps.

Also install the writeback plugin, the meta plugin, and the entries_index_tagged plugin. Installation is simply a matter of sticking the file in the right directory and editing a few configuration options at the top of the file.

Some changes have to be made to these plugins. First, the entries_index_tagged plugin wants the timestamps to be in Unix Timestamp format. Not only can MovableType NOT produce this, but, in the future, if you decided to use this feature in your new entries, coming up with a Unix Timestamp can be a pain in the ass. Therefore, we’ll modify the plugin so that the timestamps should be in YYYYMMDDHHIISS format. Just after line 104 (line 103 reads last if $thisLine =~ /^\s*$/;) add the following:

if($mtime > 0) {
    ($year,$mon,$day,$hour,$min,$sec) = ($mtime =~ m/^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})/);
    $mtime = timelocal($sec,$min,$hour,$day,$mon - 1,$year - 1900);

Additionally, the $timestamp_tag configuration variable should be set to "creation_timestamp:".

Now edit the meta plugin. Set the $meta_prefix configuration option to nothing ('').

Now edit the writeback plugin. When the writeback plugin gets a new writeback (comment or trackback) it converts all of the line endings from -newline- -carriage return- to, simple, -carriage return-. This allows the multiline data of the comment to be held on one line. Unfortunately, MovableType doesn’t support doing this, so we have to convert writeback to support multiline data fields. Go to line 164 (it reads if ( $fh->open("$writeback_dir$path/$filename.$file_extension") ) {). Delete the line after it, and continue deleting until the line that starts with my $writeback = &$blosxom::template. In between those two remaining lines, add the following:

my $ml = 0;
my $curitem = '';
foreach my $line (<$fh>) {
  if ($line =~ /^(.+?):::\[(.*)\]:::$/) {
    $param{$1} = $2;
  } elsif ($line =~ /^(.+?):::\[(.*)$/) {
    $ml = 1;
    $curitem = $1;
    $param{$1} = $2;
  } elsif ($line =~ /^(.*)\]:::$/) {
    $ml = 0;
    $param{$curitem} .= $1;
    $curitem = '';
  } elsif ($ml == 1) {
    $param{$curitem} .= $line;
  } elsif ($line =~ /^(.+?):(.*)$/) {
    $param{$1} = $2;
  } elsif ( $line =~ /^-----$/ ) {

Now, move all of the MovableType archives in the /blos/ directory in to the data directory for Blosxom. Addtionally, move all the /blos_wb/ files into the writeback directory for Blosxom.

That’s it. You’re done. If you’d like to ensure that your old links are preserved, a small web script might be in order to redirect users from one place to another. Try to work it out on your own. I’ll post an example tomorrow.

Let me know if you found this helpful or if any corrections or clarifications are needed.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>