2 use lib $FindBin::Bin.'/code';
3 use Web::Simple 'Bloggery';
5 package Bloggery::PostList;
10 my ($class, $dir) = @_;
11 bless ({ dir => $dir }, $class);
16 map { Bloggery::Post->from_file($_) }
17 sort { stat($a)->mtime <=> stat($b)->mtime }
18 grep { !/\.summary\.html$/ }
19 glob($self->{dir}.'/*.html');
23 my ($self, $name) = @_;
24 my $file = $self->{dir}."/${name}.html";
25 return unless $file && -f $file;
26 return Bloggery::Post->from_file($file);
30 my ($self, $code) = @_;
31 map $code->($_), $self->all;
34 package Bloggery::Post;
37 my ($class, $file) = @_;
38 bless({ file => $file }, $class);
42 my $name = shift->{file};
49 my $title = shift->name;
55 \do { local (@ARGV, $/) = shift->{file}; <> };
59 my $file = shift->{file};
60 $file =~ s/\.html$/.summary.html/;
61 return \'<p>No summary</p>' unless -f $file;
62 \do { local (@ARGV, $/) = $file; <> };
69 posts_dir => $FindBin::Bin.'/posts',
75 ||= Bloggery::PostList->from_dir(
76 $self->config->{posts_dir}
81 my ($self, $post) = @_;
82 $self->post_list->post($post);
87 filter_response { $self->render_html($_[1]) },
90 $self->redispatch('/index.html')
99 [ 404, [ 'Content-type', 'text/plain' ], [ 'Not found' ] ]
102 [ 405, [ 'Content-type', 'text/plain' ], [ 'Method not allowed' ] ]
107 my ($self, $data) = @_;
109 return $data if ref($data) eq 'ARRAY';
112 [ 'Content-type', 'text/html' ],
114 HTML::Tags::to_html_string(
117 <title>, $self->title_for($data), </title>,
120 <h1>, $self->title_for($data), </h1>,
122 $self->main_html_for($data),
132 my ($self, $data) = @_;
133 if ($data->isa('Bloggery::Post')) {
136 return $self->config->{title};
140 my ($self, $data) = @_;
142 if ($data->isa('Bloggery::Post')) {
144 } elsif ($data->isa('Bloggery::PostList')) {
147 my $path = '/'.$_->name.'.html';
149 <h4>, <a href="$path">, $_->title, </a>, </h4>,
150 <span class="summary">, $_->summary_html, </span>,
155 <h2>, "Don't know how to render $data", </h2>;
159 Bloggery->run_if_script;