Most recent albums:
<& table_format, dirs=>[ reverse @recent_dirs ] &> % foreach my $year (reverse sort keys %date_dirs_by_year) {Albums from <% $year %>
% foreach my $dir (@{$date_dirs_by_year{$year}}) { <& thumb_for, dir=>$dir &> % }% }
Albums from before I started going by date:
% my @blob; % while (@other_dirs) { % my @blob = splice (@other_dirs, 0, 5, ()); <& table_format, dirs=>[ @blob ] &> % } %#%# % foreach my $dir (@other_dirs) { %# <& thumb_for, dir=>$dir &> %# % } %#%#
"Best Of" albums:
<& table_format, dirs=>[ @best_dirs ] &>Albums without thumbnails:
Files:
%def thumb_for>\
<%args>
$dir
%args>
% my $smallfile = $thumbs{$dir};
% (my $htmlfile = $smallfile) =~ s/-s.jpg/.html/i;
% if (not $smallfile) {
<% $dir |h %>
% return; }
\
%def>
<%def table_format>\
<%args>
@dirs
%args>
|
<& thumb_for, dir=>$dir &>
<% $dir |h%> |
% }
%def> <%shared> my %thumbs; %shared> <%init> my $source_dir = $m->current_comp->source_dir; opendir DIR, $source_dir; my @dirent = readdir (DIR); closedir DIR; my (@dirs, @files); for (@dirent) { next if ( $_ eq "thumbs" or $_ eq "index.html" or $_ eq "." or $_ eq ".."); next if /~$/; if (-d "$source_dir/$_") { push @dirs, $_ } elsif (-f _) { push @files, $_ } } # # the special "thumbs" subdirectory contains symlinks of the form: # 20040515-12:26:40 mengwong@newbabe:~/html/mason/www.mengwong.com/photography/thumbs% ll # total 8 # drwxrwxr-x 2 mengwong mengwong 4096 May 15 12:26 ./ # drwxr-xr-x 136 mengwong mengwong 4096 May 15 12:09 ../ # lrwxrwxrwx 1 mengwong mengwong 14 May 15 12:25 20040510-merngfamily -> dsc_7940-s.jpg # lrwxrwxrwx 1 mengwong mengwong 25 May 15 12:26 little-india -> little-india-wall-1-s.JPG # 20040515-12:26:41 mengwong@newbabe:~/html/mason/www.mengwong.com/photography/thumbs% # # build %thumbs = ("20040510-merngfamily" => "dsc_7940-s.jpg", ...); opendir THUMBS, "$source_dir/thumbs"; my @thumbs = readdir (THUMBS); closedir THUMBS; for (@thumbs) { my $link = "$source_dir/thumbs/$_"; next unless -l $link; my $readlink = readlink($link); $thumbs{$_} = $readlink; } # # flesh out the thumbs for all the subdirectories, even if no specific thumb was defined in thumbs/ # foreach my $dir (@dirs) { next if $thumbs{$dir}; opendir SUBDIR, "$source_dir/$dir"; my @subdir = readdir SUBDIR; closedir SUBDIR; my %subdir; # we're looking for an image that has both -m and -s. # we break down file001-m.jpg into $subdir{file001}->{m} foreach my $file (@subdir) { if ($file =~ /(\S+)\.html$/) { $subdir{$1}->{html} = $file; } elsif ($file =~ /(\S+)-([lms]).jpg$/i) { $subdir{$1}->{$2} = $file; } } my $chosen; foreach my $id (sort keys %subdir) { if ($subdir{$id}->{m} && $subdir{$id}->{s} && $subdir{$id}->{html}) { $chosen = $subdir{$id}->{s}; last; } } if ($chosen) { $thumbs{$dir} = $chosen; } } # every dir should now have a thumb. if there's no thumb, the directory has no images with both -m -s and .html. # display directories in reverse date order where directories are named after dates. my (@recent_dirs, @date_dirs, @other_dirs, @best_dirs, @thumbless); for (@dirs) { if (/\bbest\b/) { push @best_dirs, $_; } if (not $thumbs{$_}) { push @thumbless, $_; } elsif (/^\d{6,8}(?:-\S+)?$/ and /^(199|20)/) { push @date_dirs, $_; } else { push @other_dirs, $_; } } @date_dirs = reverse sort @date_dirs; @other_dirs = sort @other_dirs; @recent_dirs = splice (@date_dirs, 0, 5); my %date_dirs_by_year; foreach my $dir (@date_dirs) { push @{$date_dirs_by_year{substr($dir,0,4)}}, $dir; } %init>