X-Git-Url: https://git.stderr.nl/gitweb?p=matthijs%2Fupstream%2Fblosxom-plugins.git;a=blobdiff_plain;f=general%2Frecententries;fp=general%2Frecententries;h=26574183cd2b8e51b0539a7d233c18be42b3f0ab;hp=0000000000000000000000000000000000000000;hb=67e5bf3facd593833bd47045602cf016192a9065;hpb=f0e04e40d8c0d902eab73fe3feede1607379ed35 diff --git a/general/recententries b/general/recententries new file mode 100644 index 0000000..2657418 --- /dev/null +++ b/general/recententries @@ -0,0 +1,110 @@ +# 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 +