12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #!/bin/sh
- REQUEST_PATH="$(echo "$REQUEST_URI" | awk -F'?' '{ print $1 }' | ./urldecode.awk)"
- handler() {
- case "$1" in
- **.md)
- bin/md2html.awk "$1"
- ;;
- **.tpl)
- eval "$(bin/template.awk "$1")"
- ;;
- **)
- cat "$1"
- ;;
- esac
- }
- handler_body_main() {
- if [ -d "$SITE_DIR/$REQUEST_PATH" ]; then
- handler "$SITE_DIR/$REQUEST_PATH"/index.*
- elif [ -f "$SITE_DIR/$REQUEST_PATH".* ]; then
- handler "$SITE_DIR/$REQUEST_PATH".*
- fi
- }
- nav_tree() {
- find "$SITE_DIR" |
- sed -E -e "$DIR_FILTER s!^$SITE_DIR!!; $DIR_CLEAN" 2>&1 |
- sort -u | awk -v req_path="$REQUEST_PATH" -F/ '
- function p(x, y, s) { for(i=0; i < x-y; i+=1) print s }
- BEGIN { lNF=2; print "<ul>" }
- {
- d = ""
- if(match($0, "/$"))
- d = "/"
- sub("/$", "") # Strip trailing / for dirs so NF is consistent
- p(NF, lNF, "<li><ul>")
- p(lNF, NF, "</ul></li>")
- lNF = NF
- bname = $NF d
- path = $0 d
- gsub(/[\-_]/, " ", bname)
- # To avoid false matches add trailing / even for plain files to act as delimiter
- pa = path
- gsub(/[^\/]$/, "&/", pa)
- if(index(req_path "/", pa) == 1)
- print "<li><a href=\"" path "\" class=\"thisPage\">»<i> " bname "</i></a></li>"
- else
- print "<li><a href=\"" path "\">› " bname "</a></li>"
- }
- END { p(lNF, 2, "</ul></li>"); print "</ul>" }'
- }
|