Added the ability to view page source on markdown-generated pages; also handle 404s better

This commit is contained in:
Matthew Connelly 2015-03-15 01:26:57 +00:00
parent ddba5cecb2
commit d0f1de2f5d
2 changed files with 15 additions and 2 deletions

View File

@ -53,6 +53,7 @@ sub readpost {
| HOEDOWN_EXT_HIGHLIGHT
| HOEDOWN_EXT_SUPERSCRIPT
| HOEDOWN_EXT_NO_INTRA_EMPHASIS);
$postm{mdsource} = $postb;
undef $postb;
if (defined $postm{date}) {
$postm{slug} = slugify($postm{title}) unless $postm{slug}; #we allow custom slugs to be defined
@ -200,16 +201,24 @@ get '/page/:id' => sub {
return paginate params->{id};
};
get '/wrote/:yyyy/:mm/:slug' => sub {
pass unless params->{yyyy} =~ /^[0-9]{4}$/ and params->{mm} =~ /^(?:0[1-9]|1[0-2])$/ and params->{slug} =~ /^[a-z0-9\-]+$/i;
pass unless params->{yyyy} =~ /^[0-9]{4}$/ and params->{mm} =~ /^(?:0[1-9]|1[0-2])$/ and params->{slug} =~ /^[a-z0-9\-]+(?:\.md)?$/i;
$page->param(SOURCEVIEW => 1) if params->{slug} =~ /\.md$/;
$page->param(ISPOST => 1);
get_post params->{yyyy}, params->{mm}, params->{slug} or pass;
return $page->output;
};
get '/:extpage' => sub {
pass unless params->{extpage} =~ /^[a-z0-9\-]+$/i;
pass unless params->{extpage} =~ /^[a-z0-9\-]+(?:\.md)?$/i;
$page->param(SOURCEVIEW => 1) if params->{extpage} =~ /\.md$/;
$page->param(ISPOST => 0);
get_page params->{extpage} or pass;
return $page->output;
};
# 404
any qr{.*} => sub {
return redirect '/' if request->path =~ /index(?:\.(?:htm|p)l?)?$/;
status 'not_found';
return redirect '/404.html';
};
start;

View File

@ -1,3 +1,6 @@
<TMPL_IF NAME="SOURCEVIEW">
<TMPL_VAR NAME="mdsource">
<TMPL_ELSE>
<TMPL_INCLUDE NAME="head.inc">
<TMPL_IF NAME="INDEX">
<TMPL_LOOP NAME="POSTS">
@ -7,3 +10,4 @@
<TMPL_INCLUDE NAME="post.inc">
</TMPL_IF>
<TMPL_INCLUDE NAME="foot.inc">
</TMPL_IF>