#!/usr/bin/perl -w use strict; use File::Path; use Fatal qw/mkpath symlink open close/; scalar @ARGV == 2 or die; my $SRC=$ARGV[0]; my $TGT=$ARGV[1]; # list of languages my @lang = glob("$SRC/index.html.*") or die; map { s{^.*html\.}{} } @lang; # map "ja.euc-jp" to "ja/", ... my %lpath; foreach my $l (@lang) { my $t=$l; $t =~ s{\..*$}{}; $lpath{$l}="$t/"; } my @html=`find $SRC -name *.html` or die; chomp(@html); map { s{^$SRC/}{} } @html; foreach my $h (@html) { my $dir=""; if ($h =~ m{^(.*/)}) { $dir=$1; } for my $l (@lang) { my $tdir="$TGT/$lpath{$l}"; -d "$tdir$dir" || mkpath("$tdir$dir"); my $updir=$dir; $updir =~ s{[^/]+}{..}g; if ($l eq "en") { conv("$SRC/$h.en", "$tdir$h", $h); } elsif ( -f "$SRC/$h.$l" ) { conv("$SRC/$h.$l", "$tdir$h", $h); } else { symlink("${updir}../en/$h", "$tdir$h"); } } } open(my $out, ">", "$TGT/index.html"); print $out '
', '', "\n\n$l |