'
}
# Don't change var name or trailing ';', some dirs change the filter!
dirfilter = '/\/[._]/d; /'^$forbidden_uri_chars^'/d; /\/robots.\txt$/d; /\/sitemap\.txt$/d; s,^\./,,; s,\.md$,,; s,\.html,,; s,\.txt,,; '
# To be used from config files
fn hide_paths {
for(i in $*)
dirfilter = $dirfilter^'/^'$i'$/d; '
}
# Sidebar
fn menu {
ls -F $1 | sed $dirfilter | awk -F/ '
BEGIN { print "
" }
END { print "
" }
# Should add \. to the list of allowed chars in file names, but need to find a way to filter out .txt and so on
/^([a-zA-Z0-9+_\-]+[\/*]?)+$/ && $NF != "index" {
isdir = match($0, "/$")
sub("[*/]$", "")
path = bname = $0
sub("^(.*/)?([0-9]+_)?", "", bname)
gsub("_", " ", bname)
if(isdir) {
bname = bname "/"
path = $0 "/"
}
if(index(ENVIRON["REQUEST_URI"] "/", "/" path) == 1) {
if(isdir) {
print "
"
}'
}
fn gensidebar {
@{
cd $sitedir
menu .
}
}
fn sortedBlogPostList {
# the /./ is added so we can sort -t. and order only the file name
if (! ~ $#* 0)
ls $*^'/./' | grep '/[0-9]+.*\.md$'| sort -r -t. +1
}
fn gen_blog_post_title {
title=`{basename $1 | sed 's/^[0-9\-]*_(.*)\.md$/\1/; s/_/ /g' }
permlink= `{echo $1 | sed 's,^/[a-z/]*www/,/,; s,^sites/[^/]*/*/,/,; s/\.md$//' }
du=`{ls -l $1}
by = ''
if (! ~ $#blogAuthor 0)
by='By '$"blogAuthor
if not if (~ $#blogDirs 1)
by='By '$du(4)
echo '##' $"title^' *( '$by Last mod: $du(7 8 9) ' )*'
}
# Handlers
fn set_handler {
handler = $1
shift
handler_args = $*
}
fn md_handler { cat $* | $formatter }
fn tpl_handler { template $1 }
fn html_handler {
cat $1 | /bin/sed '0,/<[Bb][Oo][Dd][Yy][^>]*>/d; /<\/[Bb][Oo][Dd][Yy]>/,$d'
}
fn txt_handler {
echo '
'
# XXX Insering a blank line between lines in input is good for fortunes.txt, but maybe not for other .txt files
# XXX Words are not broken, even if they are way beyond 82 chars long
cat $1 |sed 's/$/\n/g; s/\</g; s/>/\>/g' |fmt -l 82 -j
echo '