-
Notifications
You must be signed in to change notification settings - Fork 1
/
make-directory.pl
executable file
·61 lines (44 loc) · 1.61 KB
/
make-directory.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
#!/usr/bin/env perl
# make-directory.pl - given a few pre-configurations, output a HTML directory of study carrels
# usage: ./bin/make-directory.pl > /export/reader/carrels/INDEX.HTM
# Eric Lease Morgan <emorgan@nd.edu.
# May 26, 2020 - first move to Project CORD
# configure
use constant TEMPLATE => './etc/directory.htm';
use constant TABLE => './etc/table.tsv';
use constant VIEW => "<a href='./##SHORTNAME##/'>view</a>";
use constant DOWNLOAD => "<a href='./##SHORTNAME##/study-carrel.zip'>download</a>";
# require
use strict;
# initialize
my $table = TABLE;
my @rows = ();
# open the data file and process each line; build a list of rows
open TSV, "< $table" or die "Can't open $table ($!)\n";
while ( <TSV> ) {
# parse
chop;
my( $shortname, $date, $keyword, $items, $words, $flesch, $size ) = split( "\t", $_ );
# build a link to the given study carrel
my $view = VIEW;
$view =~ s/##SHORTNAME##/$shortname/eg;
my $download = DOWNLOAD;
$download =~ s/##SHORTNAME##/$shortname/eg;
# build the row and update the list of them
my $row = "<tr><td>$shortname ($view, $download)</td><td>$date</td><td>$keyword</td><td class='right'>$items</td><td class='right'>$words</td><td class='right'>$flesch</td><td class='right'>$size</td></tr>";
push( @rows, $row );
}
# sort the rows by name, slurp up the template, substitute, and output
my $rows = join( "\n", sort( @rows ) );
my $html = &slurp( TEMPLATE );
$html =~ s/##ROWS##/$rows/e;
print $html;
# done
exit;
sub slurp {
my $f = shift;
open ( F, $f ) or die "Can't open $f: $!\n";
my $r = do { local $/; <F> };
close F;
return $r;
}