-
Notifications
You must be signed in to change notification settings - Fork 2
/
whi2html.pl
78 lines (67 loc) · 2.22 KB
/
whi2html.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
$reverse = 1;
if ($reverse) {
open HI, "tac .whistory|";
} else {
open HI, ".whistory";
}
# use full width
$pre = 0;
print "<pre>\n" if $pre;
my $lastdate, $lasturl;
while (<HI>) {
chop();
if (/(\S+?)T((\d\d:\d\d):\d\d)\S+\s+(\S+)\s+(\S+)\s+(\S+)(|\s+(.*))/) {
my ($date, $hhmmss, $hhmm, $type, $url, $ansi, $title) = ($1, $2, $3, $4, $5, $6);
#print "date=$date\nhhmm=$hhmm\nhhmmss=$hhmmss\ntype=$type\nurl=$url\nansi=$ansi\ntitle=$title\n\n";
unless ($date eq $lastdate) {
print "<h2>$date</h2>\n";
$lastdate = $date;
}
next if $url eq $lasturl;
$lasturl= $url;
# if no title use simplified url
if ($url =~ m|duckduckgo\.com/html\?q=(.*)|i) {
$title = "Search: $1";
}
# load from .TITLE
if (!$title) {
my $ft=$ansi;
$ft =~ s/.ANSI/.TITLE/;
if (open FIL, $ft) {
$title= <FIL>;
close FIL;
}
}
if (!$title) {
$title = $url;
$title =~ s/%(..)/chr($1)/eg;
#$title =~ s:\.(org|com|net|biz)::;
$title =~ s|^https?:/+||;
$title =~ s|^www.||;
$title =~ s|[./]?html?||;
$title =~ s:\b(index|cached|images|image|picture|icon|cache|cdn|news|static|dynamic|main|desktop|large|small|medium|en|US|de|archives?)\b: :ig;
$title =~ s|fbclid=.*||;
$title =~ s|/?#?$/?||;
$title =~ s|[0-9a-f_-]{5,}| |ig;
$title =~ s|/(.*?)/([^/]{5,})$|... $2|;
$title =~ s|-+| |g;
$title =~ s| +| |g;
$title =~ s|\s*($1)\s*|$1|;
$title =~ s|\?q=([^&]+)| Seach: $1|;
$title =~ s|\?(.*)||;
$title =~ s|.?blogspot.com| Blog |;
$title =~ s|#$||g;
$title =~ s|/+$||g;
}
$title =~ s/[ \s-_\.]{2,}/ /g;
$title =~ s|^[\.\s]*(.*)[\.\s#?/]*$|$1|;
unless ($url =~ /(https:|http:|file:)/) {
$url= "http://" . $url;
}
print "$hhmm <a href=\"$url\"> $title</a>"; # <br> if not pre
print ($pre? "\n" : "<br>\n");
} else {
print STDERR "%%: $_";
}
}
print "</pre>\n";