Changeset 1618
- Timestamp:
- 08/29/06 01:37:43
- Files:
-
- branches/hackathon-summary/plagger (modified) (previous)
- branches/hackathon-summary/plagger/deps/Summary-Simple.yaml (added)
- branches/hackathon-summary/plagger/lib/Plagger.pm (modified) (1 diff)
- branches/hackathon-summary/plagger/lib/Plagger/Plugin/Summary/Auto.pm (modified) (1 diff)
- branches/hackathon-summary/plagger/lib/Plagger/Plugin/Summary/Simple.pm (added)
- branches/hackathon-summary/plagger/lib/Plagger/Util.pm (modified) (2 diffs)
- branches/hackathon-summary/plagger/t/core/summarize.t (deleted)
- branches/hackathon-summary/plagger/t/plugins/Summary-Simple (added)
- branches/hackathon-summary/plagger/t/plugins/Summary-Simple/base.t (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/hackathon-summary/plagger/lib/Plagger.pm
r1551 r1618 293 293 } 294 294 $self->autoload_plugin({ module => 'Summary::Auto' }); 295 $self->autoload_plugin({ module => 'Summary::Simple' }); 295 296 296 297 for my $feed ($self->subscription->feeds) { branches/hackathon-summary/plagger/lib/Plagger/Plugin/Summary/Auto.pm
r1556 r1618 23 23 text => $args->{entry}->body, 24 24 }); 25 26 unless (defined $summary) { 27 $summary = Plagger::Util::summarize($args->{entry}->body); 28 } 29 $args->{entry}->summary($summary); 25 $args->{entry}->summary($summary) if defined $summary; 30 26 } 31 27 } branches/hackathon-summary/plagger/lib/Plagger/Util.pm
r1607 r1618 2 2 use strict; 3 3 our @ISA = qw(Exporter); 4 our @EXPORT_OK = qw( strip_html dumbnail decode_content extract_title load_uri mime_type_of filename_for summarize);4 our @EXPORT_OK = qw( strip_html dumbnail decode_content extract_title load_uri mime_type_of filename_for ); 5 5 6 6 use Encode (); … … 208 208 } 209 209 210 sub summarize {211 my($text) = @_;212 $text = Plagger::Text->new_from_text($text) unless ref $text;213 214 if ($text->is_html) {215 # HTML: grab first block paragraph, or until first <br />216 my $html = $text->data;217 if ($html =~ m|^\s*<(\w*)\s*[^>]*>(.*?)</\1>|s && $HTML::Tagset::isBodyElement{lc($1)}) {218 return "<$1>$2</$1>";219 } elsif ($html =~ m!^(.*?)<br\s*/?>!s) {220 return $1;221 } else {222 return $html;223 }224 } else {225 # text: substring with 255 bytes226 if (length($text) > 255) {227 return substr($text, 0, 255) . "...";228 } else {229 return $text;230 }231 }232 }233 234 210 1;
