Changeset 98

Show
Ignore:
Timestamp:
02/18/06 10:45:53
Author:
miyagawa
Message:
  • Supports en localization. Fixes #49
  • Sort entries reverse chronologically. Refs #12
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger/Plugin/CustomFeed/Mailman.pm

    r49 r98  
    33use base qw( Plagger::Plugin ); 
    44 
     5use List::Util qw(min); 
     6use DateTime::Locale; 
    57use Encode; 
    68use Plagger::UserAgent; 
     
    6062 
    6163    my $year  = $now->year; 
    62     my $title = ($content =~ /<title>(.*?) $year/)[0]; # xxx hack 
     64 
     65    # TODO: only tested with ja and en localization 
     66    my $month = join '|', @{ DateTime::Locale->load('en_us')->month_names }; 
     67    my $title = ($content =~ /<title>(?:The )?(.*?) (?:(?:$month) )?$year/)[0]; 
    6368 
    6469    my $feed = Plagger::Feed->new; 
     
    6772    $feed->link($self->conf->{url}); # base 
    6873 
    69     my $i = 0; 
    70     my $items = $self->conf->{fetch_items} || 20; 
     74    my @matches; 
    7175    while ($content =~ m!<LI><A HREF="(\d+\.html)">(.*?)\n</A><A NAME="(\d+)">&nbsp;</A>\n<I>(.*?)\n</I>!g) { 
    72         last if $i++ >= $items; 
     76        push @matches, { 
     77            link    => $1, 
     78            subject => $2, 
     79            id      => $3, 
     80            from    => $4, 
     81        }; 
     82    } 
    7383 
    74         my($link, $subject, $id, $from) = ($1, $2, $3, $4); 
     84    my $items = min( $self->conf->{fetch_items} || 20, scalar(@matches)); 
     85    @matches  = reverse @matches[-$items .. -1]; 
     86 
     87    for my $match (@matches) { 
    7588        if ($self->conf->{trim_prefix}) { 
    7689            # don't use $id here. Some Re: messages contain original ID 
    77             $subject =~ s/\[$title \d+\]\s+//; 
     90            $match->{subject} =~ s/\[$title \d+\]\s+//; 
    7891        } 
    7992 
    8093        my $entry = Plagger::Entry->new; 
    81         $entry->title($subject); 
    82         $entry->link($base_url . $link); 
    83         $entry->author($from); 
     94        $entry->title($match->{subject}); 
     95        $entry->link($base_url . $match->{link}); 
     96        $entry->author($match->{from}); 
    8497 
    8598        $feed->add_entry($entry);