Changeset 1583

Show
Ignore:
Timestamp:
08/24/06 16:12:47
Author:
miyagawa
Message:

Filter::TruePermalink?: remove redirectors.yaml. Instead introduced 'follow_redirect' config which defaults to 1, to check redirection by issuing GET

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/plagger/lib/Plagger/Plugin/Filter/TruePermalink.pm

    r933 r1583  
    1212    my $self = shift; 
    1313    $self->SUPER::init(@_); 
     14    $self->conf->{follow_redirect} = 1 unless exists $self->conf->{follow_redirect}; 
    1415    $self->load_plugins; 
    1516} 
     
    3233    my $data = YAML::LoadFile($file); 
    3334    if (ref($data) eq 'ARRAY') { 
    34         push @{$self->{redirectors}}, { follow_link => "^(?:" . join("|", @$data) . ")" }; 
     35        # redirectors.yaml ... make it backward compatible to ignore 
    3536    } else { 
    3637        push @{$self->{plugins}}, $data; 
     
    99100    } 
    100101 
    101     unless ($count) { 
    102         for my $red (@{ $self->{redirectors} }) { 
    103             next unless $red->{follow_link}; 
    104             if ($link =~ /$red->{follow_link}/i) { 
    105                 my $url = $self->follow_redirect($link); 
    106                 if ($url && $url ne $link) { 
    107                     $count++; 
    108                     $rewritten = $url; 
    109                     last; 
    110                 } 
    111             } 
     102    # No match to known sites. Try redirect by issuing GET 
     103    if (!$count && $self->conf->{follow_redirect}) { 
     104        my $url = $self->follow_redirect($link); 
     105        if ($url && $url ne $link) { 
     106            $count++; 
     107            $rewritten = $url; 
    112108        } 
    113109    } 
     
    127123        "redirector:$link", 
    128124        sub { 
     125            Plagger->context->log(debug => "Issuing GET to $link to follow redirects"); 
    129126            my $ua  = Plagger::UserAgent->new; 
    130127            my $res = $ua->simple_request( HTTP::Request->new(GET => $link) ); 
     
    137134    ); 
    138135 
    139     Plagger->context->log(debug => "Resolving redirection of $link: $url") if $url; 
     136    Plagger->context->log(debug => "Resolved redirection of $link => $url") if $url; 
    140137 
    141138    return $url; 
     
    165162tries to rewrite url of them. 
    166163 
     164=head1 CONFIG 
     165 
     166=over 4 
     167 
     168=item follow_redirect 
     169 
     170If set to 1, this plugin issues GET request to entry permalinks to see 
     171if the server returns 301 or 302 redirect to other URL. Defaults to 1. 
     172 
     173=back 
     174 
    167175=head1 PATTERN FILES 
    168176 
  • trunk/plagger/t/plugins/Filter-TruePermalink/oreilly.t

    r1301 r1583  
    11use t::TestPlagger; 
    22 
     3test_requires_network; 
    34plan 'no_plan'; 
    45run_eval_expected;