本を読む

読書やコンピュータなどに関するメモ

P::P::Publish::TagCloud更新

 HTML::TagCloudの出力するCSSが0.34で修正された結果、P::P::Publish::TagCloudがエラーになるようになった。そこで更新。古いHTML::TagCloudでも同じ結果になるようにした。

package Plagger::Plugin::Publish::TagCloud;
use strict;
use warnings;
use base qw ( Plagger::Plugin );

our $VERSION = 0.02;

use Encode;
use HTML::TagCloud;
use File::Spec;

sub register {
    my ($self, $context) = @_;
    $context->register_hook(
        $self,
        'publish.feed' => \&feed,
    );
}

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

    my $conf = $self->conf;
    my $f = $args->{feed};

    my %tagcount;
    for my $e ($f->entries) {
        for my $t (@{$e->tags}){
            $tagcount{$t}++;
        }
    }

    my $cloud = HTML::TagCloud->new;
    while ((my $k, my $c) =  each %tagcount) {
        $cloud->add($k, '', $c);
    }

    my $html = $cloud->html_and_css($self->conf->{maxtags} || undef);
    $html =~ s/line-height: \d+px/line-height: 1/; # for HTML::TagCloud < 0.34

    my $file = Plagger::Util::filename_for($f, $self->conf->{filename} || "%i.html");
    my $filepath = File::Spec->catfile($self->conf->{dir}, $file);
    $context->log(info => "save TagCloud for " . $f->link . " to $filepath");

    open my $output, ">:utf8", $filepath or $context->error("$filepath: $!");
    print $output $html;
    close $output;
}

1;

__END__

=head1

Plagger::Plugin::Publish::TagCloud - Publish feeds as TagCloud

=head1 SYNOPSIS

  - module: Publish::TagCloud
    config:
      dir: /tmp/tag
      filename: output.html
      maxtags: 10

=head1 CONFIG

=head2 dir

Directory to save csv files in.

=head2 filename

Filename to be used to create csv files. It defaults to C<%i.html>. It
supports the following format like printf():

=head2 maxtags

Numbers of tags to output.

=head1 AUTHOR

Masakazu Takahashi

=head1 SEE ALSO

L<Plagger>, L<HTML::TagCloud>

=cut

コメント

コメントの投稿

管理者にだけ表示を許可する

トラックバック

http://emasaka.blog65.fc2.com/tb.php/161-82e5e993

 | HOME | 

Categories

Recent Entries

Recent Comments

Recent Trackbacks

Appendix

emasaka

emasaka

フリーター。
連絡先はこのへん

Monthly


FC2Ad