root/trunk/plagger/lib/Plagger/Plugin/Filter/TagsToTitle.pm

Revision 740 (checked in by charsbar, 14 years ago)

Added Filter::TagsToTitle?

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 package Plagger::Plugin::Filter::TagsToTitle;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 our $VERSION = '0.01_01';
6
7 sub register {
8     my ($self, $context) = @_;
9     $context->register_hook(
10         $self,
11         'update.feed.fixup' => \&filter,
12     );
13 }
14
15 sub filter {
16     my ($self, $context, $args) = @_;
17
18     my $add_to = $self->conf->{add_to} || 'left';
19
20     foreach my $entry ($args->{feed}->entries) {
21         my @tags  = $entry->tags ? map { "[$_]" } @{ $entry->tags } : ();
22         my $title = $entry->title;
23
24         # XXX: should I see (or erase) original tags? optional?
25         # my @orig = $title =~ /\[[^]]+\]\s*/g;
26         # $title =~ s/\[[^]]+\]\s*//g;
27
28         push    @tags, $title if $add_to eq 'left';
29         unshift @tags, $title if $add_to eq 'right';
30
31         $entry->title( join(' ', @tags) );
32     }
33 }
34
35 1;
36
37 __END__
38
39 =head1 NAME
40
41 Plagger::Plugin::Filter::TagsToTitle - add tags to entry title
42
43 =head1 SYNOPSIS
44
45   - module: Filter::TagsToTitle
46     config:
47       add_to: left
48
49 =head1 CONFIG
50
51 =over 4
52
53 =item add_to
54
55 Specify 'left' or 'right' of the title. Defaults to 'left'.
56
57 =back
58
59 =head1 AUTHOR
60
61 Kenichi Ishigaki
62
63 =head1 SEE ALSO
64
65 L<Plagger>
66
67 =cut
Note: See TracBrowser for help on using the browser.