corehandlers.sh 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/sh
  2. REQUEST_PATH="$(echo "$REQUEST_URI" | awk -F'?' '{ print $1 }' | ./urldecode.awk)"
  3. handler() {
  4. case "$1" in
  5. **.md)
  6. bin/md2html.awk "$1"
  7. ;;
  8. **.tpl)
  9. eval "$(bin/template.awk "$1")"
  10. ;;
  11. **)
  12. cat "$1"
  13. ;;
  14. esac
  15. }
  16. handler_body_main() {
  17. if [ -d "$SITE_DIR/$REQUEST_PATH" ]; then
  18. handler "$SITE_DIR/$REQUEST_PATH"/index.*
  19. elif [ -f "$SITE_DIR/$REQUEST_PATH".* ]; then
  20. handler "$SITE_DIR/$REQUEST_PATH".*
  21. fi
  22. }
  23. nav_tree() {
  24. find "$SITE_DIR" |
  25. sed -E -e "$DIR_FILTER s!^$SITE_DIR!!; $DIR_CLEAN" 2>&1 |
  26. sort -u | awk -v req_path="$REQUEST_PATH" -F/ '
  27. function p(x, y, s) { for(i=0; i < x-y; i+=1) print s }
  28. BEGIN { lNF=2; print "<ul>" }
  29. {
  30. d = ""
  31. if(match($0, "/$"))
  32. d = "/"
  33. sub("/$", "") # Strip trailing / for dirs so NF is consistent
  34. p(NF, lNF, "<li><ul>")
  35. p(lNF, NF, "</ul></li>")
  36. lNF = NF
  37. bname = $NF d
  38. path = $0 d
  39. gsub(/[\-_]/, " ", bname)
  40. # To avoid false matches add trailing / even for plain files to act as delimiter
  41. pa = path
  42. gsub(/[^\/]$/, "&/", pa)
  43. if(index(req_path "/", pa) == 1)
  44. print "<li><a href=\"" path "\" class=\"thisPage\">&raquo;<i> " bname "</i></a></li>"
  45. else
  46. print "<li><a href=\"" path "\">&rsaquo; " bname "</a></li>"
  47. }
  48. END { p(lNF, 2, "</ul></li>"); print "</ul>" }'
  49. }