Two years is not such a long time

I used to have a blog, but I stopped writing two years ago. I’m going to try to start again, and my first step is switching from MovableType to WordPress by mostly following Tony’s example. I also convinced Karen to switch too, by moving her blog so she didn’t have much choice.

I needed to perform the same Kwiki format cleanup that Tony did, but I wanted a different permalink structure: I prefer the date and name based option in WordPress. So I didn’t need to hack the WordPress import script or worry about matching IDs. Instead I needed to generate a list of redirects, one for every blog entry. I wrote a short Perl script to create the list from the Movable Type export:

#!/usr/bin/perl
use strict;

my $user = shift or die "usage: $0 user\n";

local $/ = "--------\n";

while(<>) {
  my ($id) = /^ID: (\d+)/m;
  $id = sprintf "%06d", $id;
  my ($title) = /^TITLE: (.*)$/m;
  $title = lc $title;
  $title =~ s/\s+/-/g;
  $title =~ s/[^\w-]//g;
  my ($m,$d,$y) = m{^DATE: (\d+)/(\d+)/(\d+)}m;
  print "Redirect permanent /$user/archives/$id.html
    http://martian.org/$user/$y/$m/$d/$title\n";
}

1 comment

Comments are closed.