word: enlarge marked cover images
[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 li.large > figure {
31         grid-row: span 2;
32         grid-column: span 2;
33 }
34 @media (min-width: 600px) and (min-height: 400px) {
35         p + ul > li:first-child > figure {
36                 grid-row: span 3;
37                 grid-column: span 3;
38         }
39 }
40
41 figure:hover ~ ul figure,
42 figure:hover ~ ul figcaption {
43         background: #CCC;
44         color: #000;
45 }
46 figure:hover ~ ul figcaption {
47         background: rgba(255, 255, 255, .5);
48 }
49
50 figure, figcaption {
51         transition: all .5s ease-in;
52 }
53 li.parent:hover > figure > figcaption,
54 figure:hover > figcaption {
55         font-size: 175%;
56         right: 50%;
57         bottom: 50%;
58         transform: translate(50%, 50%);
59         margin-left: -60%; /* keep width */
60 }
61 </style>
62 EOT
63 });
64
65 :>
66 <h1>Words</h1>
67
68 <p>
69 Under construction.
70 Zie ook <a href="/dieren">dieren</a>.
71 </p>
72
73 <:
74 my $table = do $wordlist or die $@ // $!;
75
76 sub showimg {
77         my ($name) = @_;
78         my ($imgname) = $name =~ /^([\w -]+)/;
79         $name =~ s/\w{4} [^aoeuiyc\W] [rl]?+ \K (?= [^aoeuiy\W] [rl]? [aoeuiy] \w)/&shy;/gx;
80         $name =~ s{/(.*)}{ <small>($1)</small>}g;
81         my $hidden = $name =~ s/\?$//;
82         my $alt = $name;
83         $name = "<q>$name</q>" if $name =~ s/\?$//;
84         $name = "<figcaption>$name</figcaption>";
85
86         if ($imgname and -e ($img = "data/word/eng/$imgname.jpg")) {
87                 $name .= sprintf '<img src="/%s" alt="%s" />', $img, $imgname;
88         }
89         return sprintf '<figure%s>%s</figure>', $hidden && !exists $get{v} && ' hidden', $name;
90 }
91
92 sub printimgs {
93         say '<ul>';
94         for my $row (@_) {
95                 my @type;
96                 push @type, 'parent' if defined $table->{$row};
97                 push @type, 'large'  if $row =~ /^\*/;
98                 printf '<li%s>', @type ? sprintf ' class="%s"', join ' ', @type : '';
99                 print showimg($row =~ s/^\*//r);
100                 printimgs(@{$_}) for $table->{$row} // ();
101                 print '</li>';
102         }
103         say '</ul>';
104 }
105
106 printimgs(@{$table->{''}});