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

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

don't use Text::Diff

  • 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     my $base = $entry->permalink || $args->{feed}->link;
20     unless ($base) {
21         $context->log(warn => "No base link found");
22         return;
23     }
24
25     my $resolver = HTML::ResolveLink->new(base => $base);
26     my $html = $resolver->resolve($entry->body);
27
28     if (my $count = $resolver->resolved_count) {
29         $context->log(info => "Resolved $count link(s) in " . $entry->permalink);
30         $entry->body($html);
31     }
32 }
33
34 1;
35
36 __END__
37
38 =head1 NAME
39
40 Plagger::Plugin::Filter::ResolveRelativeLink - Resolve relative links in feed content
41
42 =head1 SYNOPSIS
43
44   - module: Filter::ResolveRelativeLink
45
46 =head1 DESCRIPTION
47
48 Some feeds contain relative URIs in their content in C<<
49 <content:encoded> >> or C<< <description> >> element. That's not a
50 valid thing to do, but because RSS and content module specification
51 doesn't clearly say about it, some feeds still do it.
52
53 This plugins tries to fix the relative links in feed content, using
54 entry's permalink as a base URL.
55
56 =head1 AUTHOR
57
58 Tatsuhiko Miyagawa
59
60 =head1 SEE ALSO
61
62 L<Plagger>, L<HTML::ResolveLink>
63
64 =cut
Note: See TracBrowser for help on using the browser.