<commit_before>package Ilbot::Frontend;
use strict;
use warnings;
use 5.010;
use HTML::Template;

use Ilbot::Config qw/config template/;
use Ilbot::Date qw/today mytime/;
use Ilbot::Frontend::NickColor qw/nick_to_color/;
use Ilbot::Frontend::TextFilter qw/text_filter/;

use Config::File;
use Date::Simple qw/date/;
use IrcLog::WWW qw/my_decode/;
use HTML::Entities qw(encode_entities);
use Encode qw/encode_utf8/;

use Data::Dumper;

use constant ENTITIES => qq{<>"&};
use constant NBSP => "\xa0";


sub new {
    my ($class, %opt) = @_;
    die "Missing option 'backend" unless $opt{backend};
    return bless {backend => $opt{backend} }, $class;
}

sub backend { $_[0]{backend} }

sub index {
    my ($self, %opt) = @_;
    die "Missing option 'out_fh'" unless $opt{out_fh};
    my $template = Ilbot::Config::template('index');
    my @channels;
    my $has_images = 0;
    my $path = config(www => 'static_path');
    for my $channel (@{ $self->backend->channels }) {
        next unless $channel =~ s/^\#+//;
        my %data = (channel => $channel);

        my $filename = $channel;
        $filename =~ s/[^\w-]+//g;
        $filename = "static/images/index/$filename.png";
        if (-e "$path/$filename") {
            $data{image_path}   = $filename;
            $has_images         = 1;
        }
        push @channels, \%data;
    }

    $template->param(has_images => $has_images);
    $template->param(base_url   => config(www => 'base_url'));
    $template->param(channels   => \@channels);
    $template->output(print_to  => $opt{out_fh});
}

sub channel_index {
    my ($self, %opt) = @_;
    die "Missing option 'out_fh'"  unless $opt{out_fh};
    die "Missing option 'channel'" unless $opt{channel};
    my $t = Ilbot::Config::template('channel-index');
    my $b = $self->backend->channel(channel => '#' . $opt{channel});
    $t->param(channel   => $opt{channel});<commit_msg>fix up image paths<commit_after>package Ilbot::Frontend;
use strict;
use warnings;
use 5.010;
use HTML::Template;

use Ilbot::Config qw/config template/;
use Ilbot::Date qw/today mytime/;
use Ilbot::Frontend::NickColor qw/nick_to_color/;
use Ilbot::Frontend::TextFilter qw/text_filter/;

use Config::File;
use Date::Simple qw/date/;
use IrcLog::WWW qw/my_decode/;
use HTML::Entities qw(encode_entities);
use Encode qw/encode_utf8/;

use Data::Dumper;

use constant ENTITIES => qq{<>"&};
use constant NBSP => "\xa0";


sub new {
    my ($class, %opt) = @_;
    die "Missing option 'backend" unless $opt{backend};
    return bless {backend => $opt{backend} }, $class;
}

sub backend { $_[0]{backend} }

sub index {
    my ($self, %opt) = @_;
    die "Missing option 'out_fh'" unless $opt{out_fh};
    my $template = Ilbot::Config::template('index');
    my @channels;
    my $has_images = 0;
    my $path = config(www => 'static_path') . '/';
    for my $channel (@{ $self->backend->channels }) {
        next unless $channel =~ s/^\#+//;
        my %data = (channel => $channel);

        my $filename = $channel;
        $filename =~ s/[^\w-]+//g;
        $filename = "s/images/index/$filename.png";
        warn $filename;
        if (-e "$path/$filename") {
            $data{image_path}   = $filename;
            $has_images         = 1;
        }
        push @channels, \%data;
    }

    $template->param(has_images => $has_images);
    $template->param(base_url   => config(www => 'base_url'));
    $template->param(channels   => \@channels);
    $template->output(print_to  => $opt{out_fh});
}

sub channel_index {
    my ($self, %opt) = @_;
    die "Missing option 'out_fh'"  unless $opt{out_fh};
    die "Missing option 'channel'" unless $opt{channel};
    my $t = Ilbot::Config::template('channel-index');
    my $b = $self->backend->channel(channel => '#' . $opt{channel});
    $t->param(channel   => $opt{channel});
{'fraction_non_alphanumeric': 0.18286311389759666, 'fraction_numerical': 0.004702194357366771, 'mean_word_length': 3.226269315673289, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3060392', 'n_tokens_mistral': 1353, 'n_tokens_neox': 1320, 'n_words': 312}