word: identify thumbnail image files by id
[sheet.git] / word.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>';
        }