'
}
# Don't change var name or trailing ';', some dirs change the filter!
dirfilter = '/\/[._]/d; s,^\./,,; s,\.md$,,; s,\.html,,; '
fn hide_paths {
for(i in $*) {
dirfilter = $dirfilter^'/^'$i'$/d; '
}
}
# Sidebar
fn menu {
lsArgs = ('-F')
# XXX will not work properly for $#blogDirs > 1 and matching is hackish
if ( (! ~ $#inBlog 0) || ! ~ $#blogDirs 0 && (~ $blogDirs^/ *$1 *$1/) ) { # Work in progress XXX
lsArgs = ($lsArgs -r)
}
ls $lsArgs $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 blogTitle {
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}
echo '##' $"title^' *('By $du(4) Last mod: $du(7 8 9) ')*'
}
# Body
fn genbody {
if (test -f $body.md) {
if (! ~ $#inBlog 0)
blogTitle $body.md | $formatter
$formatter < $body.md
}
if not if (test -f $body.tpl)
template.awk $body.tpl | rc $rcargs
if not if (test -f $body.html)
cat $body.html | /bin/sed '0,/<[Bb][Oo][Dd][Yy][^>]*>/d; /<\/[Bb][Oo][Dd][Yy]>/,$d'
if not if (~ $body *.html && test -f $body)
cat $body | /bin/sed -i '0,/]*>/d;/<\/body>/,$d' # This branch is never taken?
if not if (~ $body */[bB]log/index */[bB]log//index && ~ $#blogDirs 0)
blogDirs = `{basename -d $body}
if not if (test -f pub/^$reqpath^.tpl)
template.awk pub/^$reqpath^.tpl | rc $rcargs
if not if (test -f $body.txt) {
echo '
'
# XXX Insering a blank line between lines in input is good for fortunes.txt, but probably not for other .txt files
# XXX Words are not broken, even if they are way beyond 82 chars long
cat $body.txt |sed 's/$/\n/g; s/\>/g; s/>/\</g' |fmt -l 82 -j
echo '
'
}
if not if(~ $body */index && ~ $#blogDirs 0) {
echo '
'
}
if not if(~ $#blogDirs 0) {
#echo 'Status: 404 Not Found\n\n' # should go before starting to print body
template.awk inc/404.tpl | rc $rcargs
}
if(! ~ $#blogDirs 0) {
if (! ~ $blogTitle '')
echo '