mason/dhandler (.contact): Determine the `count' strings in advance.
authorMark Wooding <mdw@distorted.org.uk>
Wed, 21 Jun 2023 09:51:34 +0000 (10:51 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Wed, 21 Jun 2023 09:56:42 +0000 (10:56 +0100)
Rather than saving the raw statistics and determining the presentation
later, just work out the presentation early.

We're going to have multiple sizes of thumbnails in contact pages soon,
and determining the presentation for each thumbnail size would be
pointless.

mason/dhandler

index 0c834b9..78f0f95 100755 (executable)
@@ -85,14 +85,19 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
 
        my $size = "medthumb";
        my %tn;
-       my (%nd, %nf);
+       my %count;
        for my $f (@$ff)
          { $tn{$f} = TrivGal::Image->new($path . $f->name)->scale($size); }
        for my $d (@$dd) {
          my $p = join_paths $path, $d->name;
          my ($ddd, $fff, $iii);
          ($ddd, $fff, $iii) = listdir join_paths $IMGROOT, $p;
-         $nd{$d} = @$ddd; $nf{$d} = @$fff;
+
+         my $count = "";
+         $count .= scalar(@$ddd) . "/" if @$ddd;
+         $count .= scalar(@$fff) if @$fff;
+         $count{$d} = $count;
+
          DIR: for (;;) {
            if (defined $iii) {
              my $index = join_paths $p, $iii->name;
@@ -125,14 +130,11 @@ Failed to find &lsquo;<% $path |h %>&rsquo;.
 % if (@$dd) {
 <h2>Subfolders</h2>
 <div class="gallery <% $size %>">
-%   for my $d (@$dd) {
-%     my $count = "";
-%     $count .= "$nd{$d}/" if $nd{$d};
-%     $count .= "$nf{$d}" if $nf{$d};
   <& .thumbnail, target => $d->name, comment => $d->comment,
                 tn => $tn{$d}, size => $size,
                 caption =>
-                  $m->interp->apply_escapes($d->name, "h") . " [$count]" &>\
+                  $m->interp->apply_escapes($d->name, "h") .
+                  " [$count{$d}]" &>\
 %   }
 </div>
 % }