keyboard/altgr/index: label modes by description character.
[sheet.git] / keyboard / altgr / index.inc.plp
index d4d8bdeabb5c7b200fe6962ff03beb9a92bfb58d..fd36e60d5cf1e3f8ff9c49bc7efdedcb47074dc9 100644 (file)
@@ -3,11 +3,12 @@ use 5.014;
 use warnings;
 use utf8;
 
-my @incs = glob 'keyboard/altgr/*.eng.inc.pl';
+my $dirbase = 'keyboard/altgr';
+my $indexfile = "$dirbase/index";
 
 Html({
        title => "altgr keyboard cheat sheets",
-       version => '1.2',
+       version => '1.3',
        description => [
                "Overview of alternate keyboard modes,",
                "offering extended Unicode characters if a modifier key",
@@ -16,9 +17,9 @@ Html({
        keywords => [qw'
                sheet cheat reference overview keyboard altgr option
        '],
-       image => 'data/keyboard/thumb/ibm-m.jpg',
+       image => "$dirbase/thumb/ibm-m.jpg",
        stylesheet => [qw( light dark circus mono red )],
-       data => ['keyboard/altgr/index.inc.plp', @incs],
+       data => ["$dirbase/index.inc.plp", "$indexfile.inc.pl"],
        raw => <<'.',
 <style>
 .keys.cmp {
@@ -32,6 +33,14 @@ Html({
 .keys.big.cmp tbody {
        font-size: 150%;
 }
+@media (max-width: 48em) {
+       .keys.big.cmp tbody {
+               font-size: 100%;
+       }
+       .keys.big.cmp tbody a {
+               white-space: normal;
+       }
+}
 .keys.cmp tbody {
        display: table-row-group;
 }
@@ -105,9 +114,14 @@ img {
 <p>Overview of available key layouts with AltGr or similar modifier keys.</p>
 
 <:
+my $idx = Data($indexfile);
+my @incs;
+push @incs, @{ $idx->{$_} } for @{ $idx->{default} };
+
 my @sample = split /(?<!\+)/, $get{sample} // 'asSci1!+1';
 require Shiar_Sheet::Keyboard;
-use List::Util qw( uniq max );
+Shiar_Sheet::Keyboard->VERSION(3.00);
+use List::Util qw( uniq max sum );
 
 my %caticon = (
        legacy  => qq{<span class=icon title="deprecated">\N{TOP HAT}</span>},
@@ -123,18 +137,15 @@ if (@sample) {
        print "<th>$_" for @sample;
        say '</tr></thead>';
 }
-my %idx = map {s/\Q.inc.pl\E$//; ($_ => eval{ Data($_) })} @incs;
-my $most = max(map { scalar keys %{$_->{def}{''}} } values %idx);
-for my $inc (sort {
-       $idx{$a}{category} cmp $idx{$b}{category} || $a cmp $b
-} keys %idx) {
+my $most = max(map { sum values %{ $_->{inventory}{''} } } %{$idx}{@incs});
+for my $inc (@incs) {
+       my $table = $idx->{$inc};
        print @sample ? '<tr><th>' : '<figure>';
-       printf '<a href="/%s">', $inc =~ s/\.eng$//r;
-       my $table = $idx{$inc};
-       my $title = $table && $table->{title} || $inc;
+       printf '<a href="/%s">', "$dirbase/$inc";
+       my $title = $table->{title} || $inc;
 
        unless (@sample) {
-               if ($table and my $img = $table->{image}) {
+               if (my $img = $table->{image}) {
                        EscapeHTML $name = $table->{imagealt} // $img =~ m{.*/([^/.]*)};
                        print qq{<img src="/$img" alt="$name" />};
                }
@@ -144,27 +155,29 @@ for my $inc (sort {
        else {
                print $title;
                print '</a>', "\n\t";
-               my $keys = Shiar_Sheet::Keyboard->new($table);
-               for my $mode ($keys->{mode} ? sort keys %{ $keys->{mode} } : '') {
-                       my %inventory;
-                       $inventory{$_}++ for grep { /^g[2-9]/ } map { s/ (?!ext).*//r }
-                               values %{ $keys->{def}{$mode} };
+               for my $mode ($table->{mode} ? sort keys %{ $table->{mode} } : '') {
                        print '<span class=graph>';
-                       print "<label>$_</label>" for $keys->{key}{$mode} =~ s/\s.*//r || ();
-                       for my $g (sort keys %inventory) {
+                       printf "<label>%s</label>", m/^(\S*)/ for $mode && $table->{mode}{$mode} || ();
+                       for my $g (sort keys %{ $table->{inventory}{$mode} }) {
                                printf '<span class="%s" style="width:%.0f%%" title="%3$d %4$s"> %s</span>',
                                        $g, $_/$most*100, $_,
                                        join(' ', map {
-                                               $keys->{flag}{$_}[0] || 'extra'  # legend label of each class
+                                               $table->{flag}{$_}[0] || 'extra'  # legend label of each class
                                        } reverse split / /, $g)
-                                       for $inventory{$g};
+                                       for $table->{inventory}{$mode}{$g};
                        }
                        say '</span>';
                }
                print "\t<td class=ni>";
-               print join ' ', map { $caticon{$_} // () } split m{/}, $keys->{category};
+               print join ' ', map { $caticon{$_} // () } split m{/}, $table->{category} // '';
                say '';
-               $keys->print_key('', $_, $keys->{def}{''}{$_} // 'ni') for @sample;
+               if (my $keys = eval {
+                       my $keydata = Data("$dirbase/$inc.eng");
+                       Shiar_Sheet::Keyboard->new($keydata)
+               }) {
+                       $keys->print_key('', $_, ($keys->{def}{''}{$_} // ['ni']) =~ s/ mode\S*//r)
+                               for @sample;
+               }
                say '</tr>';
        }
 }