|
Revision 316
(checked in by miyagawa, 3 years ago)
|
- Adding Publish::OPML
- Added templatize method to $context
|
- Property svn:keywords set to
Id Revision
|
| Line | |
|---|
| 1 |
package Plagger::Plugin::Publish::OPML; |
|---|
| 2 |
use strict; |
|---|
| 3 |
use base qw( Plagger::Plugin ); |
|---|
| 4 |
|
|---|
| 5 |
use Plagger::Date; |
|---|
| 6 |
use File::Spec; |
|---|
| 7 |
|
|---|
| 8 |
sub init { |
|---|
| 9 |
my $self = shift; |
|---|
| 10 |
$self->SUPER::init(@_); |
|---|
| 11 |
my $output = $self->conf->{filename} |
|---|
| 12 |
or Plagger->context->error("filename is missing"); |
|---|
| 13 |
} |
|---|
| 14 |
|
|---|
| 15 |
sub register { |
|---|
| 16 |
my($self, $context) = @_; |
|---|
| 17 |
$context->register_hook( |
|---|
| 18 |
$self, |
|---|
| 19 |
'publish.feed' => \&feed, |
|---|
| 20 |
'publish.finalize' => \&finalize, |
|---|
| 21 |
); |
|---|
| 22 |
} |
|---|
| 23 |
|
|---|
| 24 |
sub feed { |
|---|
| 25 |
my($self, $context, $args) = @_; |
|---|
| 26 |
unless ($args->{feed}->type =~ /^smartfeed:/) { |
|---|
| 27 |
push @{ $self->{_feeds} }, $args->{feed}; |
|---|
| 28 |
} |
|---|
| 29 |
} |
|---|
| 30 |
|
|---|
| 31 |
sub finalize { |
|---|
| 32 |
my($self, $context, $args) = @_; |
|---|
| 33 |
my $out = $context->templatize($self, 'opml.tt', { |
|---|
| 34 |
feeds => $self->{_feeds}, |
|---|
| 35 |
now => Plagger::Date->now, |
|---|
| 36 |
}); |
|---|
| 37 |
|
|---|
| 38 |
my $path = $self->conf->{filename}; |
|---|
| 39 |
$context->log(info => "Writing OPML to $path"); |
|---|
| 40 |
|
|---|
| 41 |
open my $fh, ">:utf8", $path or $context->error("$path: $!"); |
|---|
| 42 |
print $fh $out; |
|---|
| 43 |
close $fh; |
|---|
| 44 |
} |
|---|
| 45 |
|
|---|
| 46 |
1; |
|---|
| 47 |
|
|---|
| 48 |
__END__ |
|---|
| 49 |
|
|---|
| 50 |
=head1 |
|---|
| 51 |
|
|---|
| 52 |
Plagger::Plugin::Publish::OPML - Publish OPML files based on your subcscription |
|---|
| 53 |
|
|---|
| 54 |
=head1 SYNOPSYS |
|---|
| 55 |
|
|---|
| 56 |
- module: Publish::OPML |
|---|
| 57 |
config: |
|---|
| 58 |
filename: /path/to/subscription.opml |
|---|
| 59 |
|
|---|
| 60 |
=head1 AUTHOR |
|---|
| 61 |
|
|---|
| 62 |
Tatsuhiko Miyagawa |
|---|
| 63 |
|
|---|
| 64 |
=head1 SEE ALSO |
|---|
| 65 |
|
|---|
| 66 |
L<Plagger> |
|---|
| 67 |
|
|---|
| 68 |
=cut |
|---|