| 1 |
=== lib/Plagger/Plugin/Publish/Feed.pm |
|---|
| 2 |
================================================================== |
|---|
| 3 |
--- lib/Plagger/Plugin/Publish/Feed.pm (revision 25114) |
|---|
| 4 |
+++ lib/Plagger/Plugin/Publish/Feed.pm (local) |
|---|
| 5 |
|
|---|
| 6 |
} |
|---|
| 7 |
|
|---|
| 8 |
my %formats = ( |
|---|
| 9 |
- 'u' => sub { my $s = $_[0]->url; $s =~ s!^https?://!!; $s }, |
|---|
| 10 |
- 'l' => sub { my $s = $_[0]->link; $s =~ s!^https?://!!; $s }, |
|---|
| 11 |
- 't' => sub { $_[0]->title }, |
|---|
| 12 |
- 'i' => sub { $_[0]->id }, |
|---|
| 13 |
+ 'u' => '[% feed.url | dirify %]', |
|---|
| 14 |
+ 'l' => '[% feed.link | dirify %]', |
|---|
| 15 |
+ 't' => '[% feed.title | dirify %]', |
|---|
| 16 |
+ 'i' => '[% feed.id | dirify %]' |
|---|
| 17 |
); |
|---|
| 18 |
|
|---|
| 19 |
my $format_re = qr/%(u|l|t|i)/; |
|---|
| 20 |
|
|---|
| 21 |
my($self, $feed) = @_; |
|---|
| 22 |
|
|---|
| 23 |
my $file = $self->conf->{filename} || |
|---|
| 24 |
- '%i.' . ($self->conf->{format} eq 'RSS' ? 'rss' : 'atom'); |
|---|
| 25 |
- $file =~ s{$format_re}{ |
|---|
| 26 |
- $self->safe_filename($formats{$1}->($feed)) |
|---|
| 27 |
- }egx; |
|---|
| 28 |
- $file; |
|---|
| 29 |
-} |
|---|
| 30 |
+ '[% feed.id | dirify %].' . lc($self->conf->{format}); |
|---|
| 31 |
|
|---|
| 32 |
-sub safe_filename { |
|---|
| 33 |
- my($self, $path) = @_; |
|---|
| 34 |
- $path =~ s![^\w\s]+!_!g; |
|---|
| 35 |
- $path =~ s!\s+!_!g; |
|---|
| 36 |
- $path; |
|---|
| 37 |
+ $file =~ s/$format_re/$formats{$1}/g |
|---|
| 38 |
+ and Plagger->context->log(error => "Use of %(u|l|t|i) is deprecated."); |
|---|
| 39 |
+ |
|---|
| 40 |
+ Plagger->context->templatize(\$file, { feed => $feed }); |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
1; |
|---|
| 44 |
=== lib/Plagger/Template.pm |
|---|
| 45 |
================================================================== |
|---|
| 46 |
--- lib/Plagger/Template.pm (revision 25114) |
|---|
| 47 |
+++ lib/Plagger/Template.pm (local) |
|---|
| 48 |
|
|---|
| 49 |
LOAD_TEMPLATES => [ |
|---|
| 50 |
Template::Provider::Encoding->new({ INCLUDE_PATH => $paths }), |
|---|
| 51 |
], |
|---|
| 52 |
+ FILTERS => { |
|---|
| 53 |
+ dirify => \&Plagger::Util::dirify, |
|---|
| 54 |
+ }, |
|---|
| 55 |
STASH => Template::Stash::ForceUTF8->new, |
|---|
| 56 |
}); |
|---|
| 57 |
} |
|---|
| 58 |
=== lib/Plagger/Util.pm |
|---|
| 59 |
================================================================== |
|---|
| 60 |
--- lib/Plagger/Util.pm (revision 25114) |
|---|
| 61 |
+++ lib/Plagger/Util.pm (local) |
|---|
| 62 |
|
|---|
| 63 |
package Plagger::Util; |
|---|
| 64 |
use strict; |
|---|
| 65 |
our @ISA = qw(Exporter); |
|---|
| 66 |
-our @EXPORT_OK = qw( strip_html ); |
|---|
| 67 |
+our @EXPORT_OK = qw( strip_html dirify ); |
|---|
| 68 |
|
|---|
| 69 |
use HTML::Entities; |
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
HTML::Entities::decode($html); |
|---|
| 73 |
} |
|---|
| 74 |
|
|---|
| 75 |
+sub dirify { |
|---|
| 76 |
+ my $path = shift; |
|---|
| 77 |
+ $path =~ s![^\w\s]+!_!g; |
|---|
| 78 |
+ $path =~ s!\s+!_!g; |
|---|
| 79 |
+ $path; |
|---|
| 80 |
+} |
|---|
| 81 |
+ |
|---|
| 82 |
+ |
|---|
| 83 |
1; |
|---|
| 84 |
=== lib/Plagger.pm |
|---|
| 85 |
================================================================== |
|---|
| 86 |
--- lib/Plagger.pm (revision 25114) |
|---|
| 87 |
+++ lib/Plagger.pm (local) |
|---|
| 88 |
|
|---|
| 89 |
$self->{template} ||= Plagger::Template->new($self); |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|
| 92 |
+sub templatize { |
|---|
| 93 |
+ my($self, $source, $vars) = @_; |
|---|
| 94 |
+ my $tt = $self->template; |
|---|
| 95 |
+ $tt->process($source, $vars, \my $out) |
|---|
| 96 |
+ or $self->log(error => $tt->error); |
|---|
| 97 |
+ $out; |
|---|
| 98 |
+} |
|---|
| 99 |
+ |
|---|
| 100 |
1; |
|---|
| 101 |
__END__ |
|---|
| 102 |
|
|---|