Dear Home Owner, このページをアンテナに追加 RSSフィード

 | 

2006-04-17

P::P::Filter::Permalink(using assets)  P::P::Filter::Permalink(using assets) - Dear Home Owner, を含むブックマーク はてなブックマーク -  P::P::Filter::Permalink(using assets) - Dear Home Owner,  P::P::Filter::Permalink(using assets) - Dear Home Owner, のブックマークコメント

package Plagger::Plugin::Filter::Permalink;
use strict;
use base qw( Plagger::Plugin );

use DirHandle;

sub register {
    my($self, $context) = @_;
    $context->register_hook(
        $self,
        'update.entry.fixup' => \&filter,
    );
}

sub init {
    my $self = shift;
    $self->SUPER::init(@_);
    $self->load_yaml();
}

sub load_yaml {
    my $self = shift;

    my $dir = $self->assets_dir;

    my $dh = DirHandle->new($dir) or Plagger->context->error("$dir: $!");
    for my $file (grep -f $_ && $_ =~ /\.yaml$/, map File::Spec->catfile($dir, $_), sort $dh->read) {
	push @{$self->conf->{site}}, YAML::LoadFile($file);
    }
}

sub filter {
    my($self, $context, $args) = @_;

    my $sites = $self->conf->{site};
    my $permalink_orig = $args->{entry}->permalink;
    my $count = 0;

    for my $site (@$sites) {
	my $match = $site->{match};

	if($args->{entry}->permalink =~ m/$match/i) {
	    local $_ = $args->{entry}->permalink;
	    my $rewrites = ref($site->{rewrite}) ? $site->{rewrite} : [ $site->{rewrite} ];

	    for my $rewrite (@$rewrites) {
		$count += eval $rewrite;
	    }

	    $args->{entry}->link($_);
	}
    }

    if ($count) {
	$context->log(info => "Permalink $permalink_orig rewritten to " . $args->{entry}->permalink);
    }
}

1;

__END__

=head1 NAME

Plagger::Plugin::Filter::Permalink - Rewrite permalink using Regexp

=head1 SYNOPSIS

  - module: Filter::Permalink

=head1 DESCRIPTION

This plugin rewrites permalink using Regexp.

=head1 AUTHOR

youpy

=head1 SEE ALSO

L<Plagger>

=cut

assets/plugins/Filter-Permalink/rikunavi-next.yaml

match: rikunabi\-next\.yahoo\.co\.jp
rewrite:
  - s/;jsessionid=\w+//
  - s/(&|\?)__m=\d+//
  - s/(&|\?)f=\w+//
  - s/(&|\?)vos=\w+//
  - s/(&|\?)Try=\w+//

assets/plugins/Filter-Permalink/refrss.yaml

rewrite: s/\?ref=rss//
トラックバック - http://subtech.g.hatena.ne.jp/youpy/20060417
 |