latin: palm graffiti font placeholder
[sheet.git] / word.plp
index 12c90b19720203f6896b4f9fa9c3fee14ccf710b..41d2bd330aa80a5d78b2a81c3a9e08284900ffdd 100644 (file)
--- a/word.plp
+++ b/word.plp
@@ -1,6 +1,18 @@
 <(common.inc.plp)><:
 
-my $wordlist = 'wordlist.en.inc.pl';
+our $lang = $get{lang} || 'en';
+our $wordlistbase = "data/wordlist.$lang";
+
+if ($Request and $Request =~ m{\A([^/]+)}) {
+       my $page = "word/$1.plp";
+       utf8::downgrade($page); # unicode filename breaks contents encoding
+       if (-e $page) {
+               Include $page;
+               exit;
+       }
+}
+
+my $wordlist = "$wordlistbase.inc.pl";
 my $limit = $get{v} // (exists $get{v} ? 4 : 3);
 
 Html({
@@ -11,7 +23,28 @@ Html({
                language
        '],
        data => [$wordlist],
-       raw => <<'EOT',
+       raw => (exists $get{q} && <<'EOT')
+<style>
+.gallery figure {
+       grid-row: span 1 !important;
+       grid-column: span 1 !important;
+}
+.gallery figcaption {
+       /* keep hover position */
+       right: 50%;
+       bottom: 50%;
+       transform: translate(50%, 50%);
+       /* hide */
+       visibility: hidden;
+       font-size: 0 !important;
+}
+.gallery figure:active > figcaption {
+       visibility: visible;
+       font-size: 175% !important;
+}
+</style>
+EOT
+               . <<'EOT',
 <style>
 body {
        margin: 8px 1px;
@@ -31,6 +64,7 @@ if (exists $get{debug}) {
 <p>
 Under construction.
 Zie ook <a href="/dieren">dieren</a>.
+<a href="?q">Omit translations</a> to test.
 </p>
 
 <:
@@ -57,6 +91,7 @@ sub printimgs {
        say '<ul>';
        for my $row (@_) {
                my ($id, $level, $title) = split /:/, $row, 3;
+               $id or die "empty reference"; # assertion to prevent loops
                my @type;
                push @type, 'parent' if defined $table->{$id};
                push @type, 'large'  if $level =~ s/c$//;
@@ -70,5 +105,24 @@ sub printimgs {
 }
 
 say '<section class="gallery">';
-printimgs($table->{''}->[0]);
+if (exists $get{q}) {
+       my @rows;
+       if ($Request) {
+               my @query = $Request;
+               while (@query) {
+                       push @rows, grep { (split /:/)[1] <= $limit } @query;
+                       s/:.*// for @query;
+                       @query = map {$_ ? @{$_} : ()} @{$table}{@query};
+               }
+       }
+       else {
+               @rows = map {ref ? @$_ : $_} values %{$table}; # flatten categories
+       }
+       @rows = sort { rand <=> .5 } @rows;
+       $table = {};
+       printimgs(@rows);
+}
+else {
+       printimgs($Request || $table->{''}->[0]);
+}
 say '</section>';