]> www.average.org Git - mkgallery.git/blob - mkindex.pl
cc4e66f206ff244df4ca89c1286a964fbc0e8b43
[mkgallery.git] / mkindex.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use Carp;
5 use CGI qw/:html *table *Tr *center/;
6
7 my @years=();
8 my @subdirs=();
9
10 opendir(D,'.') || die "cannot open current directory: $!";
11 while (my $de=readdir(D)) {
12         next if ($de =~/^\./);
13         next unless (-d $de);
14         if ($de =~ /^\d\d\d\d$/) {
15                 push(@years,$de);
16         } else {
17                 push(@subdirs,$de);
18         }
19 }
20 closedir(D);
21
22 my @mn=(
23         '',
24         'Jan',
25         'Feb',
26         'Mar',
27         'Apr',
28         'May',
29         'Jun',
30         'Jul',
31         'Aug',
32         'Sep',
33         'Oct',
34         'Nov',
35         'Dec',
36 );
37
38 print start_html(-title=>'Gallery'),"\n";
39 print start_center,"\n";
40 print h1("Gallery Index"),"\n";
41 print start_table({-cellspacing=>3}),"\n";
42 foreach my $yr(sort @years) {
43         print start_Tr,"\n";
44         print td({-bgcolor=>"#ffc0ff"},$yr);
45         for (my $mo=1;$mo<=12;$mo++) {
46                 my $dir=sprintf "%04d/%02d",$yr,$mo;
47                 if (-d $dir) {
48                         print td({-bgcolor=>"#ffffc0"},a({-href=>$dir.'/'},$mn[$mo]));
49                 } else {
50                         print td({-bgcolor=>"#c0c0c0"},$mn[$mo]);
51                 }
52         }
53         print end_Tr,"\n";
54 }
55 print end_table,p,"\n";
56
57 print start_table({-cellspacing=>3}),"\n";
58 foreach my $sub(sort @subdirs) {
59         print Tr(td({-bgcolor=>"#ffffc0"},a({-href=>$sub.'/'},$sub)));
60 }
61 print end_table,"\n";
62
63 print end_center,"\n";
64 print end_html,"\n";