Dancer2: Rendering markdown to HTML
Hi List, I'd like to author pages as markdown files and render them when requested. I've done something similar in Dancer, now trying Dancer2. Hoping for an easy result using Dancer2::Plugin::MarkdownFilesToHTML. I am trying to get a result from this route: localhost:5000/doc/home But I can't seem to hook up the route with the rendering, and only get 404. The setup I tried follows below. An alternative would be capturing the route with a ** and rendering the page in the route handler. Does anyone have examples of this? Thanks for any ideas! config.yml ========== appname: "mimizufarm" layout: "main" charset: "UTF-8" template: "simple" auto_page: 1 plugins: MarkDownFilesToHTML: defaults: prefix: doc file_root: lib/md template: index.tt layout: main.tt generate_toc: 0 linkable_headers: 0 routes: - home: resource: 'home.md' lib/mimizufarm.pm ================= package mimizufarm; use Dancer2; use Dancer2::Plugin::MarkdownFilesToHTML; our $VERSION = '0.1'; get '/' => sub { template 'index' => { 'title' => 'mimizufarm' }; }; true; -- Joel Roth
Joel Roth wrote:
Hi List,
I'd like to author pages as markdown files and render them when requested.
I've done something similar in Dancer, now trying Dancer2.
Hoping for an easy result using Dancer2::Plugin::MarkdownFilesToHTML.
I am trying to get a result from this route:
localhost:5000/doc/home
But I can't seem to hook up the route with the rendering, and only get 404. The setup I tried follows below.
An alternative would be capturing the route with a ** and rendering the page in the route handler. Does anyone have examples of this?
Thanks for any ideas!
config.yml ==========
appname: "mimizufarm"
layout: "main"
charset: "UTF-8"
template: "simple"
auto_page: 1
plugins: MarkDownFilesToHTML: defaults: prefix: doc file_root: lib/md template: index.tt layout: main.tt generate_toc: 0 linkable_headers: 0 routes: - home: resource: 'home.md'
lib/mimizufarm.pm =================
package mimizufarm; use Dancer2; use Dancer2::Plugin::MarkdownFilesToHTML;
our $VERSION = '0.1';
get '/' => sub { template 'index' => { 'title' => 'mimizufarm' }; };
true;
the file I'd like to render is lib/md/home.md -- Joel Roth
There's simple (if not trivial) solution with a splat, FWIW. Probably there's a better way to specify the path. I was distracted looking for something more magical. Thanks, -- use Text::Markdown 'markdown'; use File::Slurper 'read_text'; get '**' => sub { my ($route) = splat; say "route: @$route"; my @route = @$route; my $file = pop @route; $file .= '.md'; my $path = path(dirname($0), '..', 'lib', 'md', @route , $file); pass if not -r $path; say "path: $path"; my $md = read_text($path); say "markdown: $md"; my $content = markdown($md); say "content: $content"; template 'index' => { title => 'mimizufarm', 'content' => $content } }; -- Joel Roth
participants (1)
-
Joel Roth