]> www.average.org Git - mkgallery.git/blob - mkindex.pl
rollback it. will go a simpler road.
[mkgallery.git] / mkindex.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 # Create per-month index assuming that directory structure is ./YYYY/MM/...
6 # non-four-numeric subtis are put on a separate list.
7 # Output to stdout (redirect >index.html if you wish)
8
9 # Copyright (c) 2006 Eugene G. Crosser
10
11 #  This software is provided 'as-is', without any express or implied
12 #  warranty.  In no event will the authors be held liable for any damages
13 #  arising from the use of this software.
14 #
15 #  Permission is granted to anyone to use this software for any purpose,
16 #  including commercial applications, and to alter it and redistribute it
17 #  freely, subject to the following restrictions:
18 #
19 #  1. The origin of this software must not be misrepresented; you must not
20 #     claim that you wrote the original software. If you use this software
21 #     in a product, an acknowledgment in the product documentation would be
22 #     appreciated but is not required.
23 #  2. Altered source versions must be plainly marked as such, and must not be
24 #     misrepresented as being the original software.
25 #  3. This notice may not be removed or altered from any source distribution.
26
27 use strict;
28 use Carp;
29 use CGI qw/:html *table *Tr *center/;
30
31 my @years=();
32 my @subdirs=();
33
34 opendir(D,'.') || die "cannot open current directory: $!";
35 while (my $de=readdir(D)) {
36         next if ($de =~/^\./);
37         next unless (-d $de);
38         if ($de =~ /^\d\d\d\d$/) {
39                 push(@years,$de);
40         } else {
41                 push(@subdirs,$de);
42         }
43 }
44 closedir(D);
45
46 my @mn=(
47         '',
48         'Jan',
49         'Feb',
50         'Mar',
51         'Apr',
52         'May',
53         'Jun',
54         'Jul',
55         'Aug',
56         'Sep',
57         'Oct',
58         'Nov',
59         'Dec',
60 );
61
62 print start_html(-title=>'Gallery'),"\n";
63 print start_center,"\n";
64 print h1("Gallery Index"),"\n";
65 print start_table({-cellspacing=>3}),"\n";
66 foreach my $yr(sort @years) {
67         print start_Tr,"\n";
68         print td({-bgcolor=>"#ffc0ff"},
69                 a({-href=>$yr.'/index.html'},$yr));
70         for (my $mo=1;$mo<=12;$mo++) {
71                 my $dir=sprintf "%04d/%02d",$yr,$mo;
72                 if (-d $dir) {
73                         print td({-bgcolor=>"#ffffc0"},
74                                 a({-href=>$dir.'/index.html'},$mn[$mo]));
75                 } else {
76                         print td({-bgcolor=>"#c0c0c0"},$mn[$mo]);
77                 }
78         }
79         print end_Tr,"\n";
80 }
81 print end_table,p,"\n";
82
83 print start_table({-cellspacing=>3}),"\n";
84 foreach my $sub(sort @subdirs) {
85         print Tr(td({-bgcolor=>"#ffffc0"},a({-href=>$sub.'/index.html'},$sub)));
86 }
87 print end_table,"\n";
88
89 print end_center,"\n";
90 print end_html,"\n";