markdown with templating
The rc-templating feature of werc really intrigued me, but I was disappointed to find out that, by default, .tpl template files aren’t shown in werc’s hirearchy, registered a new format, mdpl, which acts as both markdown and template rc. While this could be replaced with a werc “app” for every page, using templating is a lot easier.
Adding this wasn’t too hard, I just had to change a few functions, adding them
in etc/initrc.local.
I had to first add a new function to handle mdpl files, it is just a combination
of the default md_handler and tpl_handler from bin/corehandlers.rc.
fn mdpl_handler { awk -f bin/template.awk $* | rc $rcargs | $formatter }
Then I copied setup_handlers and nav_tree to add mdpl recognition.
# fn setup_handlers
if(test -f $local_path.mdpl) {
local_file=$local_path.mdpl
handler_body_main=(mdpl_handler $local_file)
}
# fn nav_tree
sed $dirfilter'/\/[^_.\/][^\/]*(\.(md|mdpl|txt|html)|\/)$/!d; s!^'$sitedir'!!; '$dirclean
Next I had to change sitemap.tpl, just adding $d^*.mdpl to the ls command.
Last thing to change are the $dirfilter and $dirclean variables in
_werc/config, so the sidebar looks alright:
dirfilter='s/\*$//; s,/+\./+,/,g; s,^\./,,; /\/[._][^\/]/d; /'$forbidden_uri_chars'/d; /\/sitemap\.xml$/d; /\/index\.(md|mdpl|html|txt|tpl)$/d; /\/(robots|sitemap)\.txt$/d; /_werc\/?$/d; '
dirclean=' s/\.(gmi|gem|md|mdpl|html|txt)$//; '