word: identify thumbnail image files by id
authorMischa POSLAWSKY <perl@shiar.org>
Mon, 15 Jun 2020 22:51:35 +0000 (00:51 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Tue, 20 Oct 2020 20:49:11 +0000 (22:49 +0200)
word.plp
writer.plp

index 78e46a573afb3806fc59b39b6512438554345b28..40cc8898cdcd8960cba3cf7df0137975f62592f7 100644 (file)
--- a/word.plp
+++ b/word.plp
@@ -37,16 +37,15 @@ Zie ook <a href="/dieren">dieren</a>.
 my $table = do $wordlist or die $@ // $!;
 
 sub showimg {
-       my ($name) = @_;
-       my ($imgname) = $name =~ /^([\w -]+)/;
+       my ($id, $name) = @_;
+       my ($imgname) = $name =~ m{^([^/]+)};
        $name =~ s/\w{4} [^aoeuiyc\W] [rl]?+ \K (?= [^aoeuiy\W] [rl]? [aoeuiy] \w)/&shy;/gx;
        $name =~ s{/(.*)}{ <small>($1)</small>}g;
        my $hidden = $name =~ s/\?$//;
-       my $alt = $name;
        $name = "<q>$name</q>" if $name =~ s/\?$//;
        $name = "<figcaption>$name</figcaption>";
 
-       if ($imgname and -e (my $img = "data/word/en/$imgname.jpg")) {
+       if ($id and -e (my $img = "data/word/en/$id.jpg")) {
                $name .= sprintf '<img src="/%s" alt="%s" />', $img, $imgname;
        }
        return sprintf '<figure%s>%s</figure>', $hidden && !exists $get{v} && ' hidden', $name;
@@ -61,7 +60,7 @@ sub printimgs {
                push @type, 'large'  if $level =~ s/c$//;
                push @type, 'level'.($level || 0);
                printf '<li%s>', @type ? sprintf ' class="%s"', join ' ', @type : '';
-               print showimg($title) if $level <= $limit;
+               print showimg($id, $title) if $level <= $limit;
                printimgs(@{$_}) for $table->{$id} // ();
                print '</li>';
        }
index 48ffd6748245eb97cef7245ae14695444eb9b35d..7cbe9e659b78d3e3b68f95fd8c4d7bcb9aa14941 100644 (file)
@@ -300,7 +300,7 @@ package Shiar_Sheet::FormRow {
        sub imagepath {
                my ($row, $col) = @_;
                return "data/word/org/$row->{id}.jpg"   if $col eq 'source';
-               return "data/word/en/$row->{form}.jpg"  if $col eq 'thumb';
+               return "data/word/en/$row->{id}.jpg"  if $col eq 'thumb';
                return;
        }
 }