4 use lib $FindBin::Bin.'/code';
5 use Web::Simple 'Bloggery';
7 package Bloggery::PostList;
12 my ($class, $dir) = @_;
13 bless ({ dir => $dir }, $class);
18 map { Bloggery::Post->from_file($_) }
19 sort { stat($a)->mtime <=> stat($b)->mtime }
20 grep { !/\.summary\.html$/ }
21 glob($self->{dir}.'/*.html');
25 my ($self, $name) = @_;
26 my $file = $self->{dir}."/${name}.html";
27 return unless $file && -f $file;
28 return Bloggery::Post->from_file($file);
32 my ($self, $code) = @_;
33 map $code->($_), $self->all;
36 package Bloggery::Post;
39 my ($class, $file) = @_;
40 bless({ file => $file }, $class);
44 my $name = shift->{file};
51 my $title = shift->name;
57 \do { local (@ARGV, $/) = shift->{file}; <> };
61 my $file = shift->{file};
62 $file =~ s/\.html$/.summary.html/;
63 return \'<p>No summary</p>' unless -f $file;
64 \do { local (@ARGV, $/) = $file; <> };
71 posts_dir => $FindBin::Bin.'/posts',
77 ||= Bloggery::PostList->from_dir(
78 $self->config->{posts_dir}
83 my ($self, $post) = @_;
84 $self->post_list->post($post);
89 filter_response { $self->render_html($_[1]) },
92 redispatch_to '/index.html';
101 [ 404, [ 'Content-type', 'text/plain' ], [ 'Not found' ] ]
104 [ 405, [ 'Content-type', 'text/plain' ], [ 'Method not allowed' ] ]
109 my ($self, $data) = @_;
111 return $data if ref($data) eq 'ARRAY';
114 [ 'Content-type', 'text/html' ],
116 HTML::Tags::to_html_string(
119 <title>, $self->title_for($data), </title>,
122 <h1>, $self->title_for($data), </h1>,
124 $self->main_html_for($data),
134 my ($self, $data) = @_;
135 if ($data->isa('Bloggery::Post')) {
138 return $self->config->{title};
142 my ($self, $data) = @_;
144 if ($data->isa('Bloggery::Post')) {
146 } elsif ($data->isa('Bloggery::PostList')) {
149 my $path = $_->name.'.html';
151 <h4>, <a href="$path">, $_->title, </a>, </h4>,
152 <span class="summary">, $_->summary_html, </span>,
157 <h2>, "Don't know how to render $data", </h2>;
161 Bloggery->run_if_script;