#!/usr/local/plan9/bin/rc path=(. ./bin $PLAN9/bin /bin/ /usr/bin) ifs='/' { args = `{ echo -n $REQUEST_URI | sed -e 's/[^a-zA-Z_\-\/]//g' -e 's/\?.*//' } } args=`{echo $args | tr -d ' '} cd .. # config body=index siteTitle='' siteSubTitle='' title=Title template=default sidebar=sidebar . etc/initrc if (! ~ $#args 0 && ! ~ $args '') { title=$args($#args) title=`{echo $title | sed 's/_/ /' } body=`{ echo -n $"args |sed 's, ,/,g' } } l=tpl for ( i in $args ) { l = $l'/'$i if ( test -f $l/_config ) { . $l/_config } } template=tpl/$template.tpl if (! ~ $sidebar 0) { sidebar=tpl/_inc/$sidebar.tpl } if (test -d tpl/$body) { body=$body/index } body=`{echo tpl/^$"body^.md | sed 's, ,/,' } # Sidebar fn menu { ls -F $1 | sed -e 's,^./,,' -e 's,\.md$,,' | grep -v '^_'| awk ' BEGIN { print "" } /^([a-zA-Z0-9_\-]+[\/*]?)+$/ && ! /index$/ { isdir = match($0, "/$") sub("[*/]$", "") # The '*' makes no sense to me if(isdir) d = "/" bname = $0 sub("^(.*/)?([0-9]+_)?", "", bname) gsub("_", " ", bname) bname = bname d if(index(ENVIRON["REQUEST_URI"], "/" $0) == 1) { if(isdir) { print "
  • » " bname "" system("rc -c ''menu " $0 "''") } else { print "
  • » " bname "" } } else print "
  • › " bname "" print "
  • " }' } fn gensidebar { echo '

    Considered harmful:

    ' cd tpl menu . cd .. } # Body template.awk $template | rc # Debug junk #echo '
    '
    #env