/[scripts]/trunk/mt2ikiwiki.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/mt2ikiwiki.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 116 - (hide annotations)
Wed Jun 24 17:11:51 2009 UTC (14 years, 9 months ago) by dpavlin
File MIME type: text/plain
File size: 1294 byte(s)
create ikiwiki files from MovableType's export

1 dpavlin 116 #!/usr/bin/perl
2    
3     use warnings;
4     use strict;
5    
6     use Data::Dump qw/dump/;
7     use File::Slurp;
8    
9     my $debug = 0;
10    
11     my $post;
12    
13     my ($n,$v);
14    
15     while(<>) {
16     chomp;
17    
18     if ( $n ) {
19     if ( /^-----/ ) {
20     $post->{$n} .= " $v";
21     undef $n;
22     } else {
23     $v .= "$_\n";
24     next;
25     }
26     } elsif ( /([^:]+):(.*)/ ) {
27     ($n,$v) = ($1,$2);
28     if ( length($v) > 0 ) {
29     $v =~ s{^\s+}{};
30     $post->{$n} = $v;
31     undef $n;
32     }
33     } elsif ( /^$/ ) {
34     next;
35     } elsif ( /^--------$/ ) {
36    
37     warn "# post = ", dump($post) if $debug;
38    
39     my $path = "posts/$post->{BASENAME}.html";
40    
41    
42     my $tags = join(' ', map { "categories/$_" } split( m/ /, $post->{CATEGORY} ) );
43     $tags .= ' ' if $tags;
44     $tags .= join(' ', map { "tags/$_" } split( m/,/, $post->{TAGS} ) );
45    
46     my ( $dd, $mm, $yyyy, $h, $m, $s, $ampm ) = split(m{[/ :]}, $post->{DATE});
47     $h += 12 if $ampm eq 'PM';
48     my $t = sprintf('%04d-%02d-%02dT%02d:%02d:%02d', $yyyy, $mm, $dd, $h, $m, $s);
49    
50     write_file $path,
51     qq|
52     [[!meta title="$post->{TITLE}" ]]
53     [[!meta date="$t" ]]
54     [[!meta updated="$t" ]]
55     [[!tag $tags ]]
56     |
57     . "\n"
58     . $post->{BODY}
59     ;
60    
61     my $cmd = qq|svn add $path && svn commit -m "$post->{TITLE}" && svn propset -rHEAD --revprop svn:date $t.000000Z|;
62     warn "## $cmd\n";
63     system($cmd);
64     warn "# $path $t ", -s $path, $/;
65    
66     $post = {};
67     }
68    
69     }

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26