|
Revision 411
(checked in by miyagawa, 4 years ago)
|
Add new plugin Filter::Thumbnail
|
| Line | |
|---|
| 1 |
package Plagger::Plugin::Filter::Thumbnail; |
|---|
| 2 |
use strict; |
|---|
| 3 |
use base qw( Plagger::Plugin ); |
|---|
| 4 |
|
|---|
| 5 |
sub register { |
|---|
| 6 |
my($self, $context) = @_; |
|---|
| 7 |
$context->register_hook( |
|---|
| 8 |
$self, |
|---|
| 9 |
'update.feed.fixup' => \&feed, |
|---|
| 10 |
); |
|---|
| 11 |
} |
|---|
| 12 |
|
|---|
| 13 |
sub feed { |
|---|
| 14 |
my($self, $context, $args) = @_; |
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
return if $args->{feed}->image; |
|---|
| 18 |
|
|---|
| 19 |
$context->log(info => "Add thumbnail as image to " . $args->{feed}->link); |
|---|
| 20 |
$args->{feed}->image( $self->build_image($args->{feed}) ); |
|---|
| 21 |
} |
|---|
| 22 |
|
|---|
| 23 |
sub build_image { |
|---|
| 24 |
my($self, $feed) = @_; |
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
return { |
|---|
| 28 |
url => "http://img.simpleapi.net/small/" . $feed->link, |
|---|
| 29 |
title => $feed->title, |
|---|
| 30 |
link => $feed->link, |
|---|
| 31 |
width => 128, |
|---|
| 32 |
height => 128, |
|---|
| 33 |
}; |
|---|
| 34 |
} |
|---|
| 35 |
|
|---|
| 36 |
1; |
|---|
| 37 |
|
|---|
| 38 |
__END__ |
|---|
| 39 |
|
|---|
| 40 |
=head1 NAME |
|---|
| 41 |
|
|---|
| 42 |
Plagger::Plugin::Filter::Thumbnail - use Website thumbnail tool(s) to create alternative image for feeds |
|---|
| 43 |
|
|---|
| 44 |
=head1 SYNOPSIS |
|---|
| 45 |
|
|---|
| 46 |
- module: Filter::Thumbnail |
|---|
| 47 |
|
|---|
| 48 |
=head1 DESCRIPTION |
|---|
| 49 |
|
|---|
| 50 |
This plugin puts image link to website thumbnail tool when a feed |
|---|
| 51 |
doesn't have proper image set in feed itself (ala rss:image or atom:logo). |
|---|
| 52 |
|
|---|
| 53 |
For now, it uses L<http://img.simpleapi.net/> as a default (and only) |
|---|
| 54 |
URL to use with, but it should be configured when there's similar |
|---|
| 55 |
(free) serviced out there. |
|---|
| 56 |
|
|---|
| 57 |
=head1 AUTHOR |
|---|
| 58 |
|
|---|
| 59 |
Tatsuhiko Miyagawa |
|---|
| 60 |
|
|---|
| 61 |
=head1 SEE ALSO |
|---|
| 62 |
|
|---|
| 63 |
L<Plagger> |
|---|
| 64 |
|
|---|
| 65 |
=cut |
|---|