Don't hardcode filename extension
[grml.org.git] / gen_website
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Template;
7 use File::Find::Rule;
8 use File::Path qw(make_path);
9 use File::Basename qw (fileparse);
10 use File::Copy::Recursive qw(fcopy);
11
12 my $out_dir = "out/";
13
14 #find all files
15
16 my @files = File::Find::Rule->file()
17                             ->in('.');
18
19
20 #initialize template toolkit
21
22 my $template = Template->new;
23
24 if (! -d $out_dir) {
25         make_path($out_dir) or die "Could not create outdir $out_dir: $!";
26 }
27
28 foreach my $file (@files) {
29         next if $file =~ /^$out_dir/;
30         next if $file =~ /$0$/;
31         if ($file =~ /\.tt2$/) {
32                 my $output;
33                 $template->process($file, undef, \$output)
34                         || die "Could not process file \"$file\": $!";
35
36                 my ($name,$path,$suffix) = fileparse($file,qw (.tt2));
37                 open (my $fh, '>', "$out_dir/$path/$name")
38                         or die "Could not write to $file: $!";
39                 print $fh $output;
40                 close($fh);
41         } else {
42                 fcopy ($file, "$out_dir/$file") or die "Could not copy $file to $out_dir/$file: $!";
43         }
44 }