/
prunesort-v0i1
60 lines (48 loc) · 1.37 KB
/
prunesort-v0i1
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
# Blosxom Plugin: prunesort
# Author: Simon Fraser
# Version: 0.1
# Documentation: prunesort is a hack that allows for some depth control when using
# blosxom in static mode. Use it in collaboration with
# bottomupconfig, setting $prunesort::localdepth in your config
# files.
#
package prunesort;
$localdepth = 0;
sub start {
# we only make sense in static mode
return $blosxom::static_or_dynamic eq 'dynamic' ? 0 : 1;
}
sub sort
{
return sub
{
my($files_ref) = @_;
my $archive_load;
if ($blosxom::static_or_dynamic eq 'dynamic') {
$archive_load = ($blosxom::path_info_yr ne "")
} else {
$archive_load = ($blosxom::path_info =~ m/^[\/\d]+$/);
}
if ($localdepth ne 0 and !$archive_load)
{
@files_list = sort keys %$files_ref;
my $myroot = $blosxom::datadir ."/" . $blosxom::path_info;
if ($blosxom::debug)
{
printf $blosxom::debug_file "Prunesort root: $myroot (path_info $blosxom::path_info)\n";
}
$myroot =~ s/\/$//;
$myroot =~ s/\/[^\/]+\.[^\/]+$//;
foreach (@files_list)
{
if ($_ !~ /$myroot([^\/]*\/[^\/]*){0,$localdepth}$/)
{
delete $files_ref->{$_};
}
}
}
# default sort the remainder
return sort { $files_ref->{$b} <=> $files_ref->{$a} } keys %$files_ref;
};
}
1;