-
Notifications
You must be signed in to change notification settings - Fork 1
/
same_category
94 lines (68 loc) · 1.75 KB
/
same_category
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
90
91
92
93
94
# Blosxom Plugin: same_category
# Author(s): Kyo Nagashima <[email protected]>
# Version: 2006-09-21T06:11:54+09:00
# Blosxom Home/Docs/Licensing: http://www.blosxom.com/
package same_category;
use strict;
use vars qw($list);
# --- Configurable variables -----------
# include entries in sub directories or not
my $include_subdir = 0;
# number to display
my $num = 5;
# prefix
my $prefix = <<"_EOD_";
<div class="story">
<h3>Recent entries from same category</h3>
_EOD_
# postfix
my $postfix = <<"_EOD_";
</div>
_EOD_
# --- Plug-in package variables --------
my $category;
# --------------------------------------
use FileHandle;
sub start {
return 0 unless $blosxom::path_info =~ /\./;
$category = $blosxom::path_info;
$category =~ m!(.*?)([^/]+)\.(.+)$!;
$category = "$blosxom::datadir/$1";
return 1;
}
sub filter {
my($pkg, $files_ref) = @_;
(my $path = $blosxom::path_info) =~ s/\..*?$//;
my $i = 0;
foreach my $file (sort {
$files_ref->{$b} <=> $files_ref->{$a}
} keys %$files_ref) {
next if $file =~ /\Q$path\E/;
if ($include_subdir) {
next if $file !~ m!^$category!;
} else {
next if $file !~ m!^$category[^/]+$!;
}
my($url, $title) = &getinfo($file);
$list .= qq!<li><a href="$url" title="$title">$title</a></li>\n!;
$i++;
last if $i >= $num;
}
$list = $list ? qq!$prefix<ol>\n$list</ol>\n$postfix! : "";
chomp $list;
return 1;
}
sub getinfo {
my $file = shift;
my($path, $fn) = $file =~ m!^$blosxom::datadir/(?:(.*)/)?(.*)\.$blosxom::file_extension!;
my $url = "$blosxom::url/$path/$fn.$blosxom::flavour";
my $fh = new FileHandle;
my $title = '';
if (-f $file && $fh->open("< $file")) {
chomp($title = <$fh>);
$fh->close;
}
return($url, $title);
}
1;
# vim:ft=perl