]> git.sesse.net Git - webpdf/blob - last.pl
Show the rest of the filename if we truncate.
[webpdf] / last.pl
1 #! /usr/bin/perl
2 use CGI;
3 use HTML::Entities;
4 use POSIX;
5 use strict;
6 use warnings;
7 require './config.pm';
8
9 # Find the latest N PNG thumbnails. Somewhat ineffective, but I assume 
10 # we'll get to that later :-)
11 my @thumbnails = (sort { -M $a <=> -M $b } <$pdfweb::config::outputdir/*.png>);
12 my $real_show_last = scalar @thumbnails;
13 if ($real_show_last > $pdfweb::config::show_last) {
14         $real_show_last = $pdfweb::config::show_last;
15 }
16
17 # This is probably the simplest place to clean up files that we no longer
18 # need having around.
19 for my $t (@thumbnails[$pdfweb::config::show_last..$#thumbnails]) {
20         if (-M $t > $pdfweb::config::minimum_age) {
21                 (my $base = $t) =~ s/\.png$//;
22                 my @to_delete = <$base*>;
23
24                 warn "Deleting " . join(', ', @to_delete);
25                 unlink @to_delete;
26         }
27 }
28
29 # Sorry, no HTML templating. I didn't want to pull in yet another
30 # dependency :-)
31
32 print <<"EOF";
33 Content-type: text/html; charset=utf-8
34
35 <?xml version="1.0" encoding="UTF-8" ?>
36 <!DOCTYPE
37   html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
38   "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
39 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
40   <head>
41     <title>PDF converter : sesse.net</title>
42     <link rel="stylesheet" href="http://www.sesse.net/sesse.css" type="text/css" />
43     <link rel="stylesheet" href="pdfweb.css" type="text/css" />
44     <link rev="made" href="mailto:sgunderson\@bigfoot.com" />
45     <meta name="MSSmartTagsPreventParsing" content="TRUE" />
46   </head>
47   <body>
48     <h1>Last $real_show_last uploads</h1>
49     
50     <p><a href="http://pdf.sesse.net/">Back to the converter</a></p>
51 EOF
52
53 for my $t (@thumbnails[0..$pdfweb::config::show_last-1]) {
54         (my $descname = $t) =~ s/\.png$/.desc/;
55         open DESC, "<$descname"
56                 or next;
57         chomp (my $desc = <DESC>);
58         close DESC;
59
60         if (length($desc) > 30) {
61                 # Is this <abbr> abuse?
62                 $desc = HTML::Entities::encode_entities(substr($desc, 0, 30)) . " <abbr title=\"" .
63                         HTML::Entities::encode_entities($desc)
64                 . "\">...</abbr>";
65         } else {
66                 $desc = HTML::Entities::encode_entities($desc);
67         }
68
69         my $time = (stat($t))[9];
70         my $date = POSIX::strftime("%Y-%m-%d %H:%M", localtime($time));
71         $t =~ s#^.*/##;
72         (my $pdfname = $t) =~ s/\.png$//;
73
74         print <<"EOF";
75 <div class="pdfthumbnail">
76   <p class="thumb"><a href="output/$pdfname"><img src="output/$t" alt="PDF thumbnail" /></a></p>
77   <p class="desc">$desc</p>
78   <p class="date">$date</p>
79 </div>
80 EOF
81 }
82
83 print <<"EOF";
84
85     <p class="copyright">Web PDF converter, &copy; 2005 <a href="http://www.sesse.net/">Steinar H. Gunderson</a>.</p>
86   </body>
87 </html> 
88 EOF