| 1 | # Plagger::Plugin::Publish::OutlineText | ||
| 2 | # $Id: /mirror/plagger/trunk/plagger/lib/Plagger/Plugin/Publish/OutlineText.pm 4054 2006-08-24T09:32:37.524228Z miyagawa $ | ||
| 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__ |