Plagger::Plugin::Publish::Delicious作ってみた
lib/Plagger/Plugin/Publish/Delicious.pm
package Plagger::Plugin::Publish::Delicious; use strict; use base qw( Plagger::Plugin ); use Net::Delicious; use Encode; use URI::Escape qw(uri_escape uri_escape_utf8); our $VERSION = '0.01'; sub register { my($self, $context) = @_; $context->register_hook( $self, 'publish.entry.fixup' => \&add_entry, ); $self->initialize(); } sub initialize { my ($self) = @_; $self->{delicious} = Net::Delicious->new({ user => $self->conf->{username}, pswd => $self->conf->{password}, }); } sub add_entry { my ($self, $context, $args) = @_; my $cnv_ch = sub { my $string = shift; my $dst_charset = "UTF-8"; unless ( $self->conf->{src_charset} eq "UTF-8" ) { Encode::from_to( $string, $self->conf->{src_charset}, $dst_charset ); } return $string; }; my $tags = $args->{entry}->tags; if (scalar(@$tags)) { $tags = uri_escape_utf8( &$cnv_ch( my $tag_string = join ' ', @$tags)); } else { $tags = ""; } $self->{delicious}->add_post({ url => uri_escape( $args->{entry}->link ), description => uri_escape_utf8( &$cnv_ch($args->{entry}->title) ), extended => uri_escape_utf8( &$cnv_ch($args->{entry}->body) ), tags => $tags, }); sleep( $context->conf->{interval} || 2 ); } 1;
config.yaml
plugins: - module: Publish::Delicious config: username: your-username password: your-password src_charset: "UTF-8" interval: 2
src-feedとしてb.hatenaとかd.hatenaのfeed指定すると例の複数dc:subject問題でタグがうまく付いてくれません。このような場合は@{$args->{entry}->tags->[0]}で取れそうです。update.entry.fixupフェーズで適当に処理すればよいかと思われます。