# Blosxom Plugin: same_category # Author(s): Kyo Nagashima # Version: 2004-04-18 # 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_";

Recent entries from same category

_EOD_ # postfix my $postfix = <<"_EOD_";
_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 =~ /$path/; if ($include_subdir) { next if $file !~ m!^$category!; } else { next if $file !~ m!^$category[^/]+$!; } my($url, $title) = &getinfo($file); $list .= qq!
  • $title
  • \n!; $i++; last if $i >= $num; } $list = $list ? qq!$prefix
      \n$list
    \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;