forked from openSUSE/countdown.o.o
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkhtml.pl
executable file
·300 lines (284 loc) · 9.39 KB
/
mkhtml.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#!/usr/bin/perl
# vim: set ts=4 sw=4 et:
use strict;
use warnings;
my %lang = (
'en' => [ 'English' ],
'fr' => [ 'French', 'Français' ],
'de' => [ 'German', 'Deutsch' ],
'nl' => [ 'Dutch', 'Nederlands' ],
'cs' => [ 'Czech' ],
'sk' => [ 'Slovak' ],
'da' => [ 'Danish' ],
'ru' => [ 'Russian' ],
'pl' => [ 'Polish' ],
'fi' => [ 'Finnish' ],
'es' => [ 'Spanish', 'Español' ],
'it' => [ 'Italian', 'Italiano' ],
'el' => [ 'Greek' ],
'sv' => [ 'Swedish' ],
'hr' => [ 'Croatian', 'Hrvatska' ],
'nb' => [ 'Norwegian' ],
'pt' => [ 'Portuguese '],
'pt_BR' => [ 'Brazilian Portuguese' ],
'hu' => [ 'Hungarian' ],
'ro' => [ 'Romanian'] ,
'si' => [ 'Slovenian' ],
'cn' => [ 'Chinese (traditional)' ],
'tw' => [ 'Chinese (Taiwan)' ],
'id' => [ 'Indonesian' ],
'bg' => [ 'Bulgarian' ],
'ja' => [ 'Japanese (kanji)' ],
'wa' => [ 'Walloon', 'Wallon' ],
'gl' => [ 'Galician', 'Galego' ],
'ge' => [ 'Georgian' ],
);
my @order = qw(small medium large wide);
my $dir = shift;
die "must specify directory" unless defined $dir;
die "specified directory \"$dir\" does not exist or isn't a directory" unless -d $dir;
my $outfile = shift // 'index.html';
chdir($dir) or die "failed to chdir to \"$dir\": $!";
my @origs = ();
foreach my $svg (<opensuse-*.svgz>) {
# opensuse-11.4-600x100.svgz
my ($dist, $w, $h) = $svg =~ /^opensuse-(\d+\.\d+)-(\d+)x(\d+)\.svgz$/;
push(@origs, {
file => $svg,
width => $w,
height => $h,
});
}
my $out;
if ($outfile eq '-') {
$out = \*STDOUT;
} else {
open($out, '>', $outfile) or die "failed to create \"$dir/index.html\": $!";
}
print $out <<END;
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>openSUSE Counter Gallery</title>
<style type="text/css">
body {
background: #eee;
color: #444;
font-family: sans;
margin: 0 0 3em 0;
}
img {
border: none;
margin: 0;
padding: 0;
}
p {
margin: 0;
margin-bottom: 1.5em;
}
h1.section {
background: #fff;
border: 1px solid #444;
border-left: none;
border-right: none;
padding: 0.2em 0.5em 0.2em 3em;
margin: 3em 0 0.5em 0;
}
p, h2, ul, dl {
margin-left: 5%;
margin-right: 5%;
}
dt {
font-weight: bold;
text-decoration: underline;
}
p.counters a {
display: block;
float: left;
margin-right: 1.5em;
margin-bottom: 3em;
}
h1.section, p {
clear: both;
}
caption {
padding-top: 0;
margin-top: 0;
text-align: top right;
}
#title {
text-align: center;
background: #fff;
border: 1px solid #444;
font-size: 200%;
font-weight: bold;
padding: 0.5em 2em;
margin: 1em 0 2em 0;
}
ul {
margin-top: 0.1em;
padding-top: 0;
}
#index ul {
padding: 0;
}
#index li {
display: block;
float: left;
margin-right: 1em;
width: 15m;
}
#snippet {
display: block;
background: #fff;
border: 1px dashed #444;
margin-top: 0.2em;
margin-bottom: 0.2em;
padding: 0.3em 0.5em;
font-family: monospace;
font-size: 120%;
}
h2, .svgs {
clear: both;
}
h2 {
font-size: 150%;
font-weight: bold;
text-decoration: underline;
margin-top: 0;
margin-bottom: 0;
margin-right: 0;
}
.counters ul {
padding-left: 1.5em;
}
.counters li {
padding-left: 0;
margin-left: 0;
}
.counters li {
display: inline;
}
.counters li:before {
content: " | ";
}
.counters li:first-child:before {
content: none;
}
</style>
</head>
<body>
<h1 id="title">openSUSE Release Counters</h1>
<h2>How to</h2>
<p id="howto">
To display the openSUSE release counter on your website, blog, ..., use one of
the following HTML snippets, depending on the size you want to use:<br/>
<dl>
<dt>Large (400x400):</dt>
<dd><code id="snippet"><img src="http://counter.opensuse.org/large"/></code></dd>
<dt>Medium (256x256):</dt>
<dd><code id="snippet"><img src="http://counter.opensuse.org/medium"/></code></dd>
<dt>Small (130x130):</dt>
<dd><code id="snippet"><img src="http://counter.opensuse.org/small"/></code></dd>
</dl>
</p>
<p>
The language in the counter image will automatically be adapted to what the person
that <em>views</em> the page has as preferred language, falling back to English if
we do not have a translation for that language.
</p>
<p>
It is all handled on the server (counter.opensuse.org) and does not use any additional
bandwidth on your site (except for a few bytes for the additional markup as above).
The images are updated to reflect the number of remaining days before the release
(at 15:00 UTF+1) on the server, and optimally cached in the browsers of the people who
view your site.
</p>
<h2>Contribute</h2>
<p>
If you notice that your language is missing from the list, please contact
<a href="mailto:pascal.bleser\@opensuse.org">Pascal Bleser</a> with a list of the following
translations (not literal translations, but the best way to express the following
English phrases in your language):
<ul>
<li><quote><i>n</i> days to go</quote> (before the release, might also be
<quote>Only <i>n</i> days left</quote>), including whatever plurar and singular forms
are specific to the grammar of your language</li>
<li><quote>Out now!</quote>, or <quote>Available now!</quote></li>
</ul>
</p>
END
if (scalar(@origs) > 0) {
print $out <<END;
<h2>Templates</h2>
<p>
<ul>
END
foreach (sort { $a->{width} - $b->{width} } @origs) {
print $out ' <li><a href="'.$_->{file}.'">'.$_->{width}.'x'.$_->{height}.' (SVG)</a></li>', "\n";
}
print $out <<END;
</ul>
</p>
END
}
my %bylang = ();
{
foreach my $png (<*.png>) {
my ($size, $l, $ext) = $png =~ /^([^\.]+)\.([^\.]+)\.([^\.]+)$/;
my $li = (exists $lang{$l}) ? $lang{$l} : undef;
$bylang{$l} = [] unless exists $bylang{$l};
my $a = $bylang{$l};
my $r = { file => $png, size => $size, l => $l, li => $li };
(my $svg = $png) =~ s/\.png$/.svgz/;
$r->{svg} = $svg if -e $svg;
push(@$a, $r);
}
}
my %oi;
{
my $i = 0;
%oi = map { $_ => $i++ } @order;
}
print $out ' <div id="index">', "\n";
print $out ' <h2>Quick jump to language:</h2>', "\n";
print $out ' <ul>', "\n";
foreach my $l (sort keys %bylang) {
my $pngs = $bylang{$l};
next if scalar(@$pngs) < 1;
my $li = $pngs->[0]->{li};
my $h = defined($li) ? (scalar(@$li) > 1 ? $li->[1]." (".$li->[0].")" : $li->[0]) : $l;
print $out ' <li><a href="#'.$l.'">'.$h.'</a></li>', "\n";
}
print $out ' </ul>', "\n";
print $out ' </div>', "\n";
foreach my $l (sort keys %bylang) {
my $pngs = $bylang{$l};
next if scalar(@$pngs) < 1;
my $li = $pngs->[0]->{li};
my $h = defined($li) ? (scalar(@$li) > 1 ? $li->[1]." (".$li->[0].")" : $li->[0]) : $l;
print $out ' <h1 class="section"><a name="'.$l.'" />'.$h.'</h1>', "\n";
print $out ' <p class="counters">',"\n";
my @svgs = ();
foreach my $png (sort { $oi{$a->{size}} - $oi{$b->{size}} } @$pngs) {
print $out ' <a href="'.$png->{file}.'">', "\n";
print $out ' <img src="'.$png->{file}.'" />', "\n";
print $out ' </a>', "\n";
push(@svgs, $png) if exists $png->{svg};
}
if (scalar(@svgs) > 1) {
print $out ' <h2>SVGs:</h2>', "\n";
print $out ' <ul class="svgs">', "\n";
foreach (@svgs) {
print $out ' <li><a href="'.$_->{svg}.'">'.$_->{size}.'</a></li>', "\n";
}
print $out ' </ul>', "\n";
}
print $out ' </p>',"\n";
}
print $out <<END;
</body>
</html>
END
close($out) unless $outfile eq '-';