latin: palm graffiti font placeholder
[sheet.git] / word.plp
index 4d60f9a445da3fd40e177b1a07fb14ef63e6465a..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({
@@ -79,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$//;
@@ -93,7 +106,18 @@ sub printimgs {
 
 say '<section class="gallery">';
 if (exists $get{q}) {
-       my @rows = map {@$_} values %{$table}; # flatten categories
+       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);