mason/dhandler (.thumbnail + callers): Pass in pre-scaled thumbnail.
[tgal] / mason / dhandler
index d36722b..a48610c 100755 (executable)
@@ -86,12 +86,19 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
        my $size = "medthumb";
        my %tn;
        for my $f (@$ff)
-         { $tn{$f} = TrivGal::Image->new($path . $f->name); }
+         { $tn{$f} = TrivGal::Image->new($path . $f->name)->scale($size); }
        for my $d (@$dd) {
-         my ($ddd, $fff, $iii) = listdir $real . "/" . $d->name;
-         $tn{$d} = $iii ?
-           TrivGal::Image->new(join_paths $path, $d->name, $iii->name) :
-           undef;
+         my $p = join_paths $path, $d->name;
+         DIR: for (;;) {
+           my ($ddd, $fff, $iii) = listdir join_paths $IMGROOT, $p;
+           if (defined $iii) {
+             my $index = join_paths $p, $iii->name;
+             $tn{$d} = TrivGal::Image->new($index)->scale($size);
+             last DIR;
+           }
+           if (!@$ddd) { $tn{$d} = undef; last DIR; }
+           $p = join_paths $p, $ddd->[0]->name;
+         }
        }
 </%perl>
 %
@@ -112,7 +119,7 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
 <div class="gallery <% $size %>">
 %   for my $d (@$dd) {
   <& .thumbnail, target => $d->name, comment => $d->comment,
-                img => $tn{$d}, size => $size,
+                tn => $tn{$d}, size => $size,
                 caption => $m->interp->apply_escapes($d->name, "h") &>\
 %   }
 </div>
@@ -123,7 +130,7 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
 <div class="gallery <% $size %>">
 %   for my $f (@$ff) {
   <& .thumbnail, target => $f->name, comment => $f->comment,
-                img => $tn{$f}, size => $size,
+                tn => $tn{$f}, size => $size,
                 caption => $m->interp->apply_escapes($f->name, "h") &>\
 %   }
 </div>
@@ -205,7 +212,8 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
 % for my $size (qw{smallthumb medthumb bigthumb}) {
 <div class="thumbstrip <% $size %>">
 %   for my $f (@$ff) {
-  <& .thumbnail, target => $f->name, img => $img{$f}, size => $size,
+  <& .thumbnail, target => $f->name,
+                img => $img{$f}->scale($size), size => $size,
                 caption => $m->interp->apply_escapes($f->name, "h"),
                 focus => $f eq $this &>\
 %   }
@@ -250,9 +258,7 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
 %
 %###-------------------------------------------------------------------------
 <%def .thumbnail>\
-% my $tn;
-% if (defined $img) { $tn = $img->scale($size); }
-% else { $tn = "$STATICURL/folder.svg"; }
+% $tn //= "$STATICURL/folder.svg";
 % if ($focus) {
   <figure class="thumb focusthumb <% $size %>">
     <img class="thumb <% $size %>" load=lazy src="<% $tn |h %>">
@@ -273,7 +279,7 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
 %
 <%args>
        $target
-       $img
+       $tn
        $size
        $caption
        $comment => undef