root/trunk/plagger/lib/Plagger/Plugin/Filter/ResolveRelativeLink.pm

Revision 1740 (checked in by miyagawa, 14 years ago)

Filter::ResolveRelativeLink?: fixed UUV warnings

  • Property svn:keywords set to Id Revision
Line 
1 package Plagger::Plugin::Filter::ResolveRelativeLink;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use HTML::ResolveLink;
6
7 sub register {
8     my($self, $context) = @_;
9     $context->register_hook(
10         $self,
11         'update.entry.fixup' => \&filter,
12     );
13 }
14
15 sub filter {
16     my($self, $context, $args) = @_;
17     my $entry = $args->{entry};
18
19     return unless defined $entry->body;
20
21     my $base = $entry->permalink || $args->{feed}->link;
22     unless ($base) {
23         $context->log(warn => "No base link found");
24         return;
25     }
26
27     my $resolver = HTML::ResolveLink->new(base => $base);
28     my $html = $resolver->resolve($entry->body);
29
30     if (my $count = $resolver->resolved_count) {
31         $context->log(info => "Resolved $count link(s) in $base");
32         $entry->body($html);
33     }
34 }
35
36 1;
37
38 __END__
39
40 =head1 NAME
41
42 Plagger::Plugin::Filter::ResolveRelativeLink - Resolve relative links in feed content
43
44 =head1 SYNOPSIS
45
46   - module: Filter::ResolveRelativeLink
47
48 =head1 DESCRIPTION
49
50 Some feeds contain relative URIs in their content in C<<
51 <content:encoded> >> or C<< <description> >> element. That's not a
52 valid thing to do, but because RSS and content module specification
53 doesn't clearly say about it, some feeds still do it.
54
55 This plugins tries to fix the relative links in feed content, using
56 entry's permalink as a base URL.
57
58 =head1 AUTHOR
59
60 Tatsuhiko Miyagawa
61
62 =head1 SEE ALSO
63
64 L<Plagger>, L<HTML::ResolveLink>
65
66 =cut
Note: See TracBrowser for help on using the browser.