| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
package Plagger::Plugin::Publish::OutlineText; |
|---|
| 4 |
use strict; |
|---|
| 5 |
use base qw( Plagger::Plugin ); |
|---|
| 6 |
|
|---|
| 7 |
use Encode; |
|---|
| 8 |
|
|---|
| 9 |
sub register { |
|---|
| 10 |
my($self, $context) = @_; |
|---|
| 11 |
$context->register_hook( |
|---|
| 12 |
$self, |
|---|
| 13 |
'publish.feed' => \&feed, |
|---|
| 14 |
'publish.finalize' => \&finalize, |
|---|
| 15 |
) |
|---|
| 16 |
} |
|---|
| 17 |
|
|---|
| 18 |
my $feed_count = 0; |
|---|
| 19 |
|
|---|
| 20 |
sub feed { |
|---|
| 21 |
my($self, $context, $args) = @_; |
|---|
| 22 |
|
|---|
| 23 |
push @{ $self->{_feeds} }, $args->{feed}; |
|---|
| 24 |
} |
|---|
| 25 |
|
|---|
| 26 |
sub finalize { |
|---|
| 27 |
my($self, $context, $args) = @_; |
|---|
| 28 |
|
|---|
| 29 |
my $filename = $self->conf->{filename} || './outline.txt'; |
|---|
| 30 |
my $encoding = $self->conf->{encoding} || 'utf8'; |
|---|
| 31 |
|
|---|
| 32 |
my $out; |
|---|
| 33 |
foreach my $feed (@{ $self->{_feeds} }) { |
|---|
| 34 |
$out .= '.' . $feed->title . "\n"; |
|---|
| 35 |
|
|---|
| 36 |
foreach my $entry (@{ $feed->entries }) { |
|---|
| 37 |
$out .= '..' . ($entry->title || '') . "\n"; |
|---|
| 38 |
|
|---|
| 39 |
my $body = $entry->body_text; |
|---|
| 40 |
$body =~ s/^\./ \./g; |
|---|
| 41 |
$out .= $body . "\n"; |
|---|
| 42 |
} |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
$out = encode($encoding, $out); |
|---|
| 46 |
|
|---|
| 47 |
open my $fh, ">", $filename or $context->error("$filename: $!"); |
|---|
| 48 |
print $fh $out; |
|---|
| 49 |
close $fh; |
|---|
| 50 |
|
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
1; |
|---|
| 55 |
|
|---|
| 56 |
__END__ |
|---|
| 57 |
|
|---|
| 58 |
=head1 NAME |
|---|
| 59 |
|
|---|
| 60 |
Plagger::Plugin::Publish::OutlineText - Publish as hierarchical text |
|---|
| 61 |
|
|---|
| 62 |
=head1 SYNOPSIS |
|---|
| 63 |
|
|---|
| 64 |
- module: Publish::OutlineText |
|---|
| 65 |
config: |
|---|
| 66 |
filename: /path/to/outline.txt |
|---|
| 67 |
encoding: utf8 |
|---|
| 68 |
|
|---|
| 69 |
=head1 DESCRIPTION |
|---|
| 70 |
|
|---|
| 71 |
This plugin publishes feeds as hierarchical text format. |
|---|
| 72 |
|
|---|
| 73 |
=head1 CONFIG |
|---|
| 74 |
|
|---|
| 75 |
=over 4 |
|---|
| 76 |
|
|---|
| 77 |
=item filename |
|---|
| 78 |
|
|---|
| 79 |
The output filename |
|---|
| 80 |
|
|---|
| 81 |
=item encoding |
|---|
| 82 |
|
|---|
| 83 |
The encoding name for the output file. (ex: utf8, shiftjis, euc-jp) |
|---|
| 84 |
|
|---|
| 85 |
=back |
|---|
| 86 |
|
|---|
| 87 |
=head1 AUTHOR |
|---|
| 88 |
|
|---|
| 89 |
Motokazu Sekine (CHEEBOW) @M-Logic, Inc. |
|---|
| 90 |
|
|---|
| 91 |
=head1 SEE ALSO |
|---|
| 92 |
|
|---|
| 93 |
L<Plagger>, L<Encode::Supported> |
|---|
| 94 |
|
|---|
| 95 |
=cut |
|---|