learn.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/sh
  2. # learn, a simple website documentation generator
  3. # Copyright 2021,2022 Vitali64 <vitali64pmemail@protonmail.com>
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. # Please see the LICENSE file for more details.
  9. usage() {
  10. echo "Usage : ./learn.sh [OPTIONS]"
  11. echo "--help : prints this help message"
  12. echo "--clear : remove generated website"
  13. echo "--license : prints the license"
  14. }
  15. if [ "$1" = "--help" ]; then
  16. usage
  17. exit 0
  18. elif [ "$1" = "--clear" ]; then
  19. echo "[INFO] Removing generated website ..."
  20. rm -rf www/*
  21. exit 0
  22. elif [ "$1" = "--license" ]; then
  23. cat LICENSE
  24. exit 0
  25. elif [ "$1" = "" ]; then
  26. echo "learn, a simple website documentation generator"
  27. else
  28. echo "[ERROR] INVALID OPTION"
  29. usage
  30. exit 1
  31. fi
  32. # Insert header
  33. header() {
  34. cat "templates/header.html"
  35. }
  36. # Insert footer
  37. footer() {
  38. cat "templates/footer.html"
  39. }
  40. docs="$(cd docs/ && find ./*.md ./*/*.md|sed -e 's/\.md//' -e 's/.//')"
  41. list() {
  42. printf " <div class=list><h5>List</h5>"
  43. for filelink in ${docs}
  44. do
  45. name="$(head -1 docs${filelink}.md)"
  46. echo " <li><a href=\"${filelink}.html\">${name}</a></li>"
  47. done
  48. printf " </div>"
  49. }
  50. for file in ${docs}
  51. do
  52. header > "www/${file}.html"
  53. list >> "www/${file}.html"
  54. printf " <div class=\"content\">" >> "www/${file}.html"
  55. markdown "docs/${file}.md" | sed -e 's_^<h\([123]\)>\(.*\)</h\1>_<div class="h"><h\1 id="\2">\2</h\1><a aria-hidden="true" href="#\2">#</a></div>_' >> "www/${file}.html" #|sed -e 's@<h1>@<h1><a href="#?">@g' -e 's@</h1>@</a></h1>@g' >> "www/${file}.html"
  56. printf " </div>" >> "www/${file}.html"
  57. footer >> "www/${file}.html"
  58. done