UNB/ CS/ David Bremner/ blog/ files/ org2iki.pl
#!/usr/bin/perl
# David Bremner  <bremner@unb.ca> 2008-2-28
# placed in the public domain

%globaltags=();
$in_code_block=0;
$preproc=""; #"!" to use new style preprocessor directives

LINE: while(<>){
    if (m/^[*]\s*DONE\s*([^:]*)\s*:(.*):$/){
	$title=$1;
	@tags=split(":",$2);
	foreach $tag (@tags){
	    $globaltags{$tag}=1;
	}
	$filename=$title;
	$filename=~ s/\s+$//;

	$filename =~ tr/a-zA-Z0-9_.-/_/cs;
	$filename .= ".mdwn";
	open OUT,">$filename" || die "$!";
	print  OUT "<span class="createlink">&#36;&#123;preproc&#125;meta title&#61;&#92;&#34;&#36;title&#92;&#34;</span>\n"; 
        print  OUT "<span class="createlink">&#36;&#123;preproc&#125;tag  &#64;tags</span>\n";
	next LINE;
    }
    if (m/^\s+CLOSED:\s+\[(.*)\]/){
	$date=$1;
	print OUT "<span class="createlink">&#36;&#123;preproc&#125;meta date&#61;&#92;&#34;&#36;date&#92;&#34;</span>\n";
	next LINE
    }
    # convert links
    if (s|\[\[([^\]]+)\]\[([^\]]+)\]\]|[$2]($1)|){
	s|\(file:files|(/~bremner/wiki/blog/files|g;
    }
    # convert typewriter text
    s/=([^=]+)=/\`$1\`/g;

    # convert code block syntax. Not sure which is stupider
    if (s/^: /    /){
	print OUT "\n" if (!$in_code_block);
	$in_code_block=1;
    } else {
	$in_code_block=0;
    }

    # fix ad-hoc updated notes
    s/^\s*\*\*\s*UPDATE[D]?/####Update\n/;
    print OUT;
}
	

foreach $tag (keys(%globaltags)){
    open OUT,">tags/$tag.mdwn" || die "$!";
    print OUT"
This feed contains pages in the '$tag' category.

<span class="createlink">Discussion&#92;&#34; show&#61;10 actions&#61;yes</span>
";
close OUT;
}