-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathschedule_yaml2html.pl
executable file
·70 lines (67 loc) · 1.71 KB
/
schedule_yaml2html.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
#!/usr/bin/env perl
use v5.32;
use utf8;
use YAML::XS qw(LoadFile);
use Carp::Assert;
use Try::Tiny;
use Carp;
use open qw(:std :encoding(UTF-8));
assert(@ARGV >= 1, 'first argument should be input yaml filename');
assert(@ARGV >= 2, 'second argument should be whether to reverse the schedule');
my $sched = LoadFile($ARGV[0]);
my @schedule;
try{
@schedule = @{$sched};
}
catch{
croak 'schedule should be a yaml array';
};
# print html table header
say <<'EOF';
<table style="width:100%;">
<colgroup>
<col style="width: 1%">
<col style="width: 2%">
<col style="width: 95%">
</colgroup>
<thead>
<tr class="header">
<th>Speaker</th>
<th>Time ∧ Location</th>
<th>Paper</th>
</tr>
<tr class="odd">
<th></th>
<th colspan="2">Abstract</th>
</tr>
</thead>
<tbody>
EOF
@schedule = reverse @schedule if $ARGV[1];
for (@schedule){
my @event;
try{
@event = @{$_};
}
catch{
croak 'each element of the top-level array should be another array';
};
assert(@event == 5, 'each event should be a 5-tuple of (Speaker, Time ∧ Location, Paper Title, Link to Paper, Abstract)');
$event[4] =~ s/\n/<br>/g; # convert newlines to html linebreaks
say <<"EOF";
<tr class="odd">
<td>$event[0]</td>
<td>$event[1]</td>
<td><a href="$event[3]">$event[2]</a></td>
</tr>
<tr class="even">
<td></td>
<td colspan="2">$event[4]</td>
</tr>
EOF
}
# print rest of html table
say <<"EOF";
</tbody>
</table>
EOF