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);
31 package Bloggery::Post;
34 my ($class, $file) = @_;
35 bless({ file => $file }, $class);
39 my $name = shift->{file};
46 my $title = shift->name;
52 \do { local (@ARGV, $/) = shift->{file}; <> };
56 my $file = shift->{file};
57 $file =~ s/\.html$/.summary.html/;
58 return \'<p>No summary</p>' unless -f $file;
59 \do { local (@ARGV, $/) = $file; <> };
66 posts_dir => $FindBin::Bin.'/posts',
72 ||= Bloggery::PostList->from_dir(
73 $self->config->{posts_dir}
78 my ($self, $post) = @_;
79 $self->post_list->post($post);
84 filter_response { $self->render_html($_[1]) },
87 $self->redispatch('index.html')
96 [ 404, [ 'Content-type', 'text/plain' ], [ 'Not found' ] ]
99 [ 405, [ 'Content-type', 'text/plain' ], [ 'Method not allowed' ] ]
104 my ($self, $data) = @_;
106 return $data if ref($data) eq 'ARRAY';
109 [ 'Content-type', 'text/html' ],
111 HTML::Tags::to_html_string(
114 <title>, $self->title_for($data), </title>,
117 <h1>, $self->title_for($data), </h1>,
119 $self->main_html_for($data),
129 my ($self, $data) = @_;
130 if ($data->isa('Bloggery::Post')) {
133 return $self->config->{title};
137 my ($self, $data) = @_;
139 if ($data->isa('Bloggery::Post')) {
141 } elsif ($data->isa('Bloggery::PostList')) {
144 my $path = '/'.$_->name.'.html';
146 <h4>, <a href="$path">, $_->title, </a>, </h4>,
147 <span class="summary">, $_->summary_html, </span>,
152 <h2>, "Don't know how to render $data", </h2>;
156 Bloggery->run_if_script;