boh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/bin/sh
  2. boh_help() {
  3. printf "Usage: boh COMMAND [arg...]\n"
  4. printf "\nTransform a bounch of markdown files into html\n"
  5. printf "\nCommands:\n"
  6. printf "\tinit\tInitialize a dir with basic tpl\n"
  7. printf "\tbuild\tBuild the things\n"
  8. printf "\tserve\tStart python simple httpd in teh dir\n"
  9. }
  10. boh_init() {
  11. mkdir _site _assets _templates
  12. cat <<EOF > _templates/page.tpl
  13. <!doctype html>
  14. <html lang="en">
  15. <head>
  16. <meta charset="utf-8">
  17. <title>\$title</title>
  18. </head>
  19. <body>
  20. \$body
  21. </body>
  22. </html>
  23. EOF
  24. }
  25. boh_serve() {
  26. cd _site
  27. python2 -m SimpleHTTPServer
  28. }
  29. boh_check() {
  30. type markdown &> /dev/null || {
  31. >&2 echo "'markdown' is not installed"
  32. exit 1
  33. }
  34. type envsubst &> /dev/null || {
  35. >&2 echo "'envsubst' is not installed, install 'gettext' package"
  36. exit 1
  37. }
  38. }
  39. boh_build() {
  40. echo "Building all the things..."
  41. for file in `find . -type f -name "*.md"`; do
  42. title=`echo $file | rev | cut -d / -f 1 | rev | sed s/.md//`
  43. body=`cat $file | markdown`
  44. newpath="./_site/"`echo $file | rev | cut -d . -f 2 | rev`".html"
  45. mkdir -p "${newpath%/*}"
  46. export title body
  47. envsubst < "_templates/page.tpl" > "$newpath"
  48. unset title body
  49. done
  50. cp -R _assets/* _site/
  51. echo "Yay!"
  52. }
  53. boh_check
  54. case $1 in
  55. "build")
  56. boh_build
  57. ;;
  58. "init")
  59. boh_init
  60. ;;
  61. "serve")
  62. boh_serve
  63. ;;
  64. *)
  65. boh_help
  66. ;;
  67. esac