word: identify thumbnail image files by id
[sheet.git] / word.plp
1 <(common.inc.plp)><:
2
3 my $wordlist = 'wordlist.en.inc.pl';
4 my $limit = $get{v} // (exists $get{v} ? 4 : 3);
5
6 Html({
7         title => 'words cheat sheet',
8         version => '1.0',
9         description => "Visual words",
10         keywords => [qw'
11                 language
12         '],
13         data => [$wordlist],
14         raw => <<'EOT',
15 <style>
16 body {
17         margin: 8px 1px;
18 }
19 </style>
20 EOT
21 });
22
23 if (exists $get{debug}) {
24         say '<style>';
25         include 'word-debug.css';
26         say '</style>';
27 }
28 :>
29 <h1>Words</h1>
30
31 <p>
32 Under construction.
33 Zie ook <a href="/dieren">dieren</a>.
34 </p>
35
36 <:
37 my $table = do $wordlist or die $@ // $!;
38
39 sub showimg {
40         my ($id, $name) = @_;
41         my ($imgname) = $name =~ m{^([^/]+)};
42         $name =~ s/\w{4} [^aoeuiyc\W] [rl]?+ \K (?= [^aoeuiy\W] [rl]? [aoeuiy] \w)/&shy;/gx;
43         $name =~ s{/(.*)}{ <small>($1)</small>}g;
44         my $hidden = $name =~ s/\?$//;
45         $name = "<q>$name</q>" if $name =~ s/\?$//;
46         $name = "<figcaption>$name</figcaption>";
47
48         if ($id and -e (my $img = "data/word/en/$id.jpg")) {
49                 $name .= sprintf '<img src="/%s" alt="%s" />', $img, $imgname;
50         }
51         return sprintf '<figure%s>%s</figure>', $hidden && !exists $get{v} && ' hidden', $name;
52 }
53
54 sub printimgs {
55         say '<ul>';
56         for my $row (@_) {
57                 my ($id, $level, $title) = split /:/, $row, 3;
58                 my @type;
59                 push @type, 'parent' if defined $table->{$id};
60                 push @type, 'large'  if $level =~ s/c$//;
61                 push @type, 'level'.($level || 0);
62                 printf '<li%s>', @type ? sprintf ' class="%s"', join ' ', @type : '';
63                 print showimg($id, $title) if $level <= $limit;
64                 printimgs(@{$_}) for $table->{$id} // ();
65                 print '</li>';
66         }
67         say '</ul>';
68 }
69
70 say '<section class="gallery">';
71 printimgs($table->{''}->[0]);
72 say '</section>';