# Blosxom Plugin: datemap # Author: Naoki Okamura (Nyarla) # Version: 2008-03-02 # Licesen: public domain package datemap; use strict; use warnings; use FileHandle; # -- configurable variables ---------- # my $file = "$blosxom::plugin_state_dir/datemap.dat"; # -- package variables --------------- # my $datemap = { files => {}, others => {} }; my $fh = FileHandle->new; # ------------------------------------ # sub start { if ( -f $file && -r _ ) { $datemap = load($file); } return 1; } sub entries { my $sub = $blosxom::entries; return sub { my ( $files, $indexes, $others ) = $sub->(); mapping( $files, $datemap->{'files'} ); mapping( $others, $datemap->{'others'} ); save($file, $datemap); return ( $files, $indexes, $others ); } } sub mapping { my ( $files, $date ) = @_; for my $path ( keys %{ $files } ) { if ( exists $date->{$path} ) { $files->{$path} = $date->{$path}; } else { $date->{$path} = $files->{$path}; } } for my $path ( keys %{ $date } ) { delete $date->{$path} if ( ! exists $files->{$path} ); } } sub load { my ( $file ) = @_; my $data = { files => {}, others => {} }; $fh->open( $file, '<' ) or die "Couldn't open file: $file: $!"; while ( my $line = <$fh> ) { chomp $line; my ( $type, $mtime, $path ) = ( $line =~ m{^(\w+)[|](\d+)[|](.+)$} ); $data->{$type}->{$path} = $mtime; } $fh->close; return $data; } sub save { my ( $file, $data ) = @_; my $output = q{}; for my $type ( keys %{ $data } ) { for my $path ( keys %{ $data->{$type} } ) { my $mtime = $data->{$type}->{$path}; $output .= "${type}|$mtime|$path\n"; } } $fh->open( $file, '>' ) or die "Couldn't open file: $file: $!"; print $fh $output; $fh->close; } 1; __END__ =head1 NAME datemap - Fixing dated of entries =head1 AUTHOR Naoki Okamura (Nyarla) Ethotep@nyarla.netE =head1 LICENSE This code is public domain. =cut