gmisite2html/gemini2html.pl

41 lines
814 B
Perl

#! /usr/bin/perl
if(int(@ARGV)!=2) {
die "usage: gemini2html.pl sourcedir targetdir\n";
}
$SOURCE=shift;
$TARGET=shift;
@FILES=split(/\n/, `cd $SOURCE; find . -type f`);
for my $f (@FILES) {
print "$f\n";
if($f =~ m@/cgi-bin/@) {
print "skipping\n";
next;
}
$target_dir=$f;
$target_dir=~s@/[^/]+$@@;
if(!-d "$TARGET/$target_dir") {
mkdir("$TARGET/$target_dir");
}
if($f =~ /.gmi$/) {
$target=$f;
$target=~s/\.gmi$/.html/;
$target_file=$target;
$target_file=~s@.*/@@;
system("(cat header.md;gemtext2md <$SOURCE/$f)|pandoc --standalone --template template.html - -o $TARGET/$target");
open(FILE, ">$TARGET/$f");
print FILE "<meta http-equiv=\"refresh\" content=\"0; URL=$target_file\">\n";
close FILE;
} else {
system("cp $SOURCE/$f $TARGET/$f");
}
}