Skip to content

Commit

Permalink
Fix news listing
Browse files Browse the repository at this point in the history
  • Loading branch information
bentglasstube committed Jun 5, 2011
1 parent 96e4024 commit 24abbc9
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions lib/Radio.pm
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,34 @@ before_template sub {
};

get '/' => sub {
template 'news', { posts => [] };
};
my @news = ();

my $path = setting('news_path');
for (<$path/*.txt>) {
if (my $file = IO::File->new($_, 'r')) {
push @news, {
path => $_,
posted => ($file->stat)[10],
body => join('', $file->getlines),
};
} else {
warning "Couldn't open $_ for reading: $!";
}
}

@news = sort {$b->{posted} <=> $a->{posted}} @news;
my $count = setting('news_max') || 10;
@news = grep {$_} @news[0 .. ($count - 1)];

get '/index.html' => sub {
template 'news', { posts => [] };
template 'news', { posts => \@news };
};

post '/' => sub {
require_login or return;

my $id = localtime->strftime('%Y%m%d.%H%M%S');

my $path = setting('path_news') . "/$id.txt";
my $path = setting('news_path') . "/$id.txt";
my $file = IO::File->new($path, 'w');

if ($file) {
Expand Down

0 comments on commit 24abbc9

Please sign in to comment.