termcol: fix index numbers of 88-colour greyscale ramp
[sheet.git] / countries.plp
1 <(common.inc.plp)><:
2         our $VERSION = 'v1.0';
3
4 :><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
5  "http://www.w3.org/TR/html4/loose.dtd">
6 <html lang="en">
7
8 <head>
9 <meta http-equiv="content-type" content="<:= $header{content_type} :>">
10 <title>country code cheat sheet</title>
11 <meta name="description" content="Table of ISO-3166-2 country codes with the names of reserved territories.">
12 <meta name="keywords" content="country, code, cc, tld, territory, land, table">
13 <:= stylesheet(qw'light dark mono red') :>
14 <link rel="icon" type="image/png" href="/clip.png">
15 </head>
16
17 <body>
18 <h1>Country codes</h1>
19
20 <:
21 my $cc = do 'countries.inc.pl';
22
23 {
24         printf '<table class="mcmap">';
25         print '<col><colgroup span="26">';
26         for my $section (qw{thead}) {
27                 print "<$section><tr><th>↳";
28                 print '<th>', $_ for 'a' .. 'z';
29                 print "\n";
30         }
31         print '<tbody>';
32         for my $row ('a' .. 'z') {
33                 print '<tr><th>', $row;
34                 for my $col ('a' .. 'z') {
35                         my $code = $row . $col;
36                         my $country = $cc->{$code} or do {
37                                 print $code =~ /^x|^q[m-z]|^aa|^zz/ ? '<td class="X Co">' : '<td>';
38                                 next;
39                         };
40                         my ($name, $class, $short, $ref) = @$country;
41                         $ref ||= $code;
42                         local $_ = $ref;
43                         if (exists $get{show}) {
44                                 my $img = "flag/$ref.png";
45                                 $_ = sprintf '<img src="/%s" alt="%s">', $img, $ref if -e $img;
46                         }
47                         else {
48                                 $_ = $short || $name;
49                                 s/,.*//;
50                                 s/(?<=.)\(.*\)\s*//;
51                                 s/ republic\b//gi;
52                                 s/ islands?\b//gi;
53                                 s/\bthe //g;
54                                 s/ and / & /g and s/(?<=.)[a-z ]+//g;
55                                 s/\bsaint /st /gi;
56                                 s/South(?:ern)? /S-/g;
57                                 s/North(?:ern)? /N-/g;
58                                 s/New /n./g;
59                                 s/(\S)(\S+)-/$1-/g;  # strip most chars preceding dash
60                                 s/(\S{4}[b-df-hj-np-tv-xz])((?<!Austr)(?!land)\w{2,})/$1./g;  # abbreviate (at consonant)
61                                 $_ = EscapeHTML($_);
62                         }
63                         $name =~ s/([^,]*), (.*)/$2 $1/;
64                         printf "\n".'<td class="%s" title="%s">%s',
65                                 $_ ? 'X '.$class : '', EscapeHTML("$code: $name"), $_;
66                 }
67                 print "\n";
68         }
69         print "</table>\n";
70 }
71
72 :>
73 <hr>
74
75 <div class="legend">
76         <table class="glyphs"><tr>
77         <td class="X c-af">africa
78         <td class="X c-eu">europe
79         <td class="X c-as">asia
80         <td class="X c-aa">antarctica
81         <td class="X c-oc">oceania
82         <td class="X c-sa">south america
83         <td class="X c-na">north america
84         <td class="">reserved
85         <td class="X Co">user-assigned
86         </table>
87
88         <div class="right">
89                 <ul class="legend legend-set">
90                 <li><strong>show</strong>
91                         <em><:= exists $get{show} ? 'flag images' : 'english names' :></em><:=
92                                 !exists $get{show} && ' by default' :>
93                 <li>default <strong>style</strong> is
94                         <:= defined $get{style} && 'set to ' :><em><:= $style :></em>
95                 </ul>
96         </div>
97 </div>
98
99 <p class="footer">
100         <a href="/" rel="home">sheet.shiar.nl</a>/countries.<a href="/source/countries.plp"
101          rel="code" title="Written in Perl">plp</a>
102         <a href="http://git.shiar.nl/sheet.git/history/HEAD:/countries.plp"
103          rel="vcs-git" title="Git repository"><:= $VERSION :></a>
104         created by <a href="http://shiar.nl/" rel="author">Shiar</a> •
105         <a href="http://www.fsf.org/licensing/licenses/agpl-3.0.html" rel="copyright"
106          title="Licensed under the GNU Affero General Public License, version 3">AGPLv3</a>
107 </p>
108
109 </html>