word: grid layout to strictly align multiple rows
[sheet.git] / word.plp
1 <(common.inc.plp)><:
2
3 my $wordlist = 'wordlist.eng.inc.pl';
4 Html({
5         title => 'words cheat sheet',
6         version => '1.0',
7         description => "Visual words",
8         keywords => [qw'
9                 language
10         '],
11         data => [$wordlist],
12         raw => <<'EOT',
13 <style>
14 ul {
15         display: grid;
16         grid: auto-flow dense / repeat(auto-fit, minmax(200px, 1fr));
17         grid-gap: 1px;
18 }
19 li, ul ul {
20         display: contents;
21 }
22 figure {
23         overflow: hidden;
24         box-sizing: border-box;
25 }
26 figcaption > small {
27         display: inline-block;
28 }
29
30 figure:hover ~ ul figure,
31 figure:hover ~ ul figcaption {
32         background: #CCC;
33         color: #000;
34 }
35 figure:hover ~ ul figcaption {
36         background: rgba(255, 255, 255, .5);
37 }
38
39 figure, figcaption {
40         transition: all .5s ease-in;
41 }
42 li.parent:hover > figure > figcaption,
43 figure:hover > figcaption {
44         font-size: 175%;
45         right: 50%;
46         bottom: 50%;
47         transform: translate(50%, 50%);
48         margin-left: -60%; /* keep width */
49 }
50 </style>
51 EOT
52 });
53
54 :>
55 <h1>Words</h1>
56
57 <p>
58 Under construction.
59 Zie ook <a href="/dieren">dieren</a>.
60 </p>
61
62 <:
63 my $table = do $wordlist or die $@ // $!;
64
65 sub showimg {
66         my ($name) = @_;
67         my ($imgname) = $name =~ /^([\w -]+)/;
68         $name =~ s/\w{4} [^aoeuiyc\W] [rl]?+ \K (?= [^aoeuiy\W] [rl]? [aoeuiy] \w)/&shy;/gx;
69         $name =~ s{/(.*)}{ <small>($1)</small>}g;
70         my $hidden = $name =~ s/\?$//;
71         my $alt = $name;
72         $name = "<q>$name</q>" if $name =~ s/\?$//;
73         $name = "<figcaption>$name</figcaption>";
74
75         if ($imgname and -e ($img = "data/word/eng/$imgname.jpg")) {
76                 $name .= sprintf '<img src="/%s" alt="%s" />', $img, $imgname;
77         }
78         return sprintf '<figure%s>%s</figure>', $hidden && !exists $get{v} && ' hidden', $name;
79 }
80
81 sub printimgs {
82         say '<ul>';
83         for my $row (@_) {
84                 printf '<li%s>', defined $table->{$row} && ' class="parent"';
85                 print showimg($row);
86                 printimgs(@{$_}) for $table->{$row} // ();
87                 print '</li>';
88         }
89         say '</ul>';
90 }
91
92 printimgs(@{$table->{''}});