-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgen-index.pl
executable file
·89 lines (65 loc) · 2.03 KB
/
gen-index.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
#!/usr/bin/perl -w
use strict;
# Process index.html, to include the current post-0.4 changelog
# ./gen-index.pl >generated-index.html
use version;
use IO::File;
use FindBin;
use File::Spec;
use HTML::Entities;
my @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
my %m2n;
@m2n{@months} = (1 .. scalar(@months));
my $index = new IO::File(File::Spec->catfile($FindBin::Bin, 'index.html'), '<') or die "Unable to open index.html: $!";
my $htmlChanges = '';
my $latest;
my $latestDate;
my $changes = new IO::File(File::Spec->catfile($FindBin::Bin, 'XML', 'Changes'), '<') or die "Unable to open Changes: $!";
while (<$changes>) {
my $datestr;
if (my ($m, $d, $y) = /^[0-9].*([A-Z][a-z]{2})\s+(\d+).*\s([0-9]{4})\s/) {
my $mn = $m2n{$m};
$datestr = sprintf('%04d-%02d-%02d', $y, $mn, $d);
}
if (my ($vs) = /^(\d+\.\d+(?:\.\d+)?)\s+/) {
$vs = new version($vs);
if (!$latest || ($vs > $latest)) {
$latest = $vs;
$latestDate = $datestr;
}
}
s/\S+\@\S+/<xxx\@xxx>/;
last if /^0\.4\s+/;
$htmlChanges .= encode_entities($_);
}
$changes->close() or die "Unable to close Changes: $!";
print STDERR "Latest version: $latest\n";
my $rtag = "xml-writer-$latest";
print STDERR "Tag: $rtag\n";
my $baseTag = 'xml-writer-0.4';
my $diffUrl = encode_entities('https://github.com/josephw/xml-writer-perl/compare/'.$baseTag.'...'.$rtag.'#files_bucket');
while (<$index>) {
if (/<!-- CHANGELOG -->/) {
print <<"EOP";
<h3>Changes</h3>
<p>If you want to check the precise changes,
<a href="${diffUrl}" title="[xml-writer-perl] Diff of /trunk/XML/Writer.pm">this colourised diff</a>
may be useful.</p>
EOP
print "<pre>";
print $htmlChanges;
print "</pre>\n";
} elsif (my ($b, $a) = /^(.*)<!-- LATEST -->.*<!-- LATEST -->(.*)$/) {
if ($latest) {
print "${b}Release $latest${a}\n";
}
} elsif (my ($bef, $d, $aft) = /^(<p>Last modified: )(\d+-\d+-\d+)(<\/p>)/) {
if ($latestDate gt $d) {
$d = $latestDate;
}
print $bef, $d, $aft, "\n";
} else {
print $_;
}
}
$index->close() or die "Unable to close index.html: $!";