Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
33 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,38 @@ | ||
#!/bin/bash | ||
root=$1 | ||
shift | ||
plackup --port 4242 -MPlack::App::Directory -e ' | ||
enable_if { $_[0]->{REQUEST_URI} =~ /\.(md|mkdwn|markdown)$/ } | ||
#!/usr/bin/env perl | ||
use strict; | ||
use warnings; | ||
|
||
use Plack::Builder; | ||
use Plack::Runner; | ||
use Plack::App::Directory; | ||
|
||
my $root = @ARGV ? shift : '.'; | ||
|
||
# Default differently than plackup's port 5000 so we don't conflict. | ||
unshift @ARGV, '--port' => 4242; | ||
|
||
my $app = builder { | ||
my $is_markdown = qr/\.(md|mkdwn|markdown)$/i; | ||
|
||
enable_if { $_[0]->{REQUEST_URI} =~ /$is_markdown/ } | ||
SimpleContentFilter => filter => sub { | ||
use Text::MultiMarkdown qw(markdown); | ||
$_ = markdown($_, {use_wikilinks=>1}) | ||
eval { | ||
require Text::MultiMarkdown; | ||
$_ = Text::MultiMarkdown::markdown($_, { use_wikilinks => 1 }); | ||
}; | ||
return $_; | ||
}; | ||
enable_if { $_[0]->{REQUEST_URI} =~ /\.(md|mkdwn|markdown)$/ } | ||
Header => set => [qw(Content-Type text/html)]; | ||
|
||
enable_if { $_[0]->{REQUEST_URI} =~ /$is_markdown/ } | ||
Header => set => [ 'Content-Type' => 'text/html' ]; | ||
|
||
enable Expires => | ||
content_type => qr/./, | ||
expires => "now plus 1 second"; | ||
Plack::App::Directory->new({ root => q['"$root"'] })->to_app' "$@" | ||
|
||
Plack::App::Directory->new({ root => $root })->to_app; | ||
}; | ||
|
||
my $runner = Plack::Runner->new; | ||
$runner->parse_options(@ARGV); | ||
$runner->run($app); |