# Blosxom Plugin: Recent Entries
# Author(s): Gregory Bair - http://mypage.iu.edu/~gbair/
# Gavin Carr - http://www.openfusion.net/
# Version: 0.4
# Blosxom Home: http://blosxom.sourceforge.net/
# Use: insert $recententries::recententries in one of the flavour templates.
package recententries;
use strict;
use File::Spec;
#-------------- Configurable Options ----------------
# How many titles do you want to show?
my $title_num = 20;
# What comes before each title? below adds a line between each title - good for long titles.
my $title_before = qq!
!;
# What comes after?
my $title_after = qq!
!;
#----------------------------------------------------
use vars qw($recententries);
sub start { 1 }
sub filter{
my ($pkg, $files_ref) = @_;
my $tn = 1;
# Put each file name (the key of %$files_ref) into an array, but sort
# them by modification time (value) first
my @files = sort { $$files_ref{$b} <=> $$files_ref{$a} } keys %$files_ref;
foreach my $file (@files)
{
last if $tn >= $title_num;
open (STORY, $file) || die "Cannot open file $file : $!";
my @story = ;
close STORY;
# The title is always the first line in an entry. Get that.
my $storytitle = $story[0];
chomp $storytitle;
my $link = '';
# Use permalink if it's available
if (defined $permalink::root_format) {
my $rel_file = $file;
$rel_file =~ s/^$blosxom::datadir//;
$rel_file =~ s/\.$blosxom::file_extension$//;
$link = permalink::get_link( $rel_file );
}
if (! $link) {
my ($volume, $directory, $filename) = File::Spec->splitpath($file);
$filename =~ s/\.$blosxom::file_extension$//;
#Change the file into a URL we can use.
my $newvol = File::Spec->catfile($volume, $directory, '');
$newvol =~ s/$blosxom::datadir/$blosxom::url/g;
$link = "$newvol#$filename";
}
# Create our variable.
$recententries .= sprintf qq(%s%s%s\n),
$title_before, $link, $storytitle, $title_after;
# Increment $tn.
$tn++;
}
#test(%files);
1;
}
1;
__END__
=head1 NAME
Blosxom Plugin: recententries
=head1 SYNOPSIS
Purpose: Populates $recententries::recententries with a list of the most
recent entries. The number is specified by a configuration variable.
=head1 AUTHORS
Gregory Bair gregindy@softhome.net, http://mypage.iu.edu/~gbair/
Gavin Carr gavin@openfusion.net, http://www.openfusion.net/
=head1 Changelog
0.2 used qq!! instead of "" in configs
0.3 simplified the sorting algorithm at the suggestion of Todd Larason.
0.4 fixed File::Spec problems on OSes without volumes, and added L support.
=cut