/
16cat_index
46 lines (40 loc) · 1.29 KB
/
16cat_index
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
package cat_index;
use strict;
use warnings;
our $cat_index = '';
use HTML::Entities qw(encode_entities);
use Data::Dumper;
sub start {
my $data_dir = $blosxom::datadir . '/' . $blosxom::path_info;
return unless $blosxom::path_info;
unless (-d $data_dir) {
$data_dir =~ s{[^/]+$}{};
return unless -d $data_dir;
};
my @files = grep { datesort::dateforfile($_) < time } sort glob "$data_dir/*.$blosxom::file_extension";
return unless @files > 1;
$cat_index = '<div class="blog_index"><h3>Posts in this category</h3>';
$cat_index .= "\n<ul>\n";
for (@files){
my $fn = $_;
$fn =~ s{^.*/}{};
my $path = "$blosxom::url/$blosxom::path_info";
# we're not always in a directory
$path =~ s{/[^/]+$}{}g if $path =~ /\.(?:html|txt|rss|writeback)$/;
$path .= '/' . $fn;
$path =~ s/\Q$blosxom::file_extension\E$/$blosxom::flavour/;
$cat_index .= qq{<li><a href="$path">};
$cat_index .= get_title($_) . qq{</a></li>\n};
}
$cat_index .= "</ul>\n";
$cat_index .= '</div>';
}
sub get_title {
my $fn = shift;
open my $h, '<', $fn or die "Can't open file $fn for reading: $!";
my $first_line = <$h>;
close $h;
return encode_entities($first_line, q{"<>&});
}
1;
# vim: ft=perl