Git repo for my website
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

60 lines
2.6 KiB

  1. #!/bin/bash
  2. set -eo pipefail
  3. if [[ ! "${HEAD}" -gt "1" ]]; then
  4. HEAD="1"
  5. fi
  6. FINAL_PAGE="$(find -P ${HOME}/Projects/Website | grep 'index.html' | tail -1)"
  7. if [[ ${1} = 'regen' ]] || [[ ${1} = '--regen' ]]; then
  8. PAGE=$(find -P ${HOME}/Projects/Website | grep 'index.html' | head -${HEAD} | tail -1)
  9. PAGE_TITLE="$(cat ${PAGE} | head -1 | sed -e 's|<!-- ||; s| -->||')"
  10. PAGE_HTML="$(cat ${PAGE} | head -2 | tail -1 | sed -e 's|<!-- ||; s| -->||')"
  11. PAGE_CSS="$(cat ${PAGE} | head -3 | tail -1 | sed -e 's|<!-- ||; s| -->||')"
  12. PAGE_FAVICON="$(cat ${PAGE} | head -4 | tail -1 | sed -e 's|<!-- ||; s| -->||')"
  13. PAGE_CONTENT_FILE="$(cat ${PAGE} | head -5 | tail -1 | sed -e 's|<!-- ||; s| -->||')"
  14. PAGE_CONTENT="$(pandoc --from markdown --to html ${PAGE_CONTENT_FILE} | sed -e 's|/\">|/\" target=\"_blank\">|g; s|.png\">|.png\" target=\"_blank\">|g')"
  15. DESTINATION_DIR="$(echo ${PAGE} | sed -e 's|index.html||')"
  16. fi
  17. if [[ ! -z "${1}" ]] && [[ ! -z "${2}" ]] && [[ ! -z "${3}" ]] && [[ ! -z "${4}" ]] && [[ ! -z "${5}" ]] && [[ ! -z "${6}" ]]; then
  18. PAGE_TITLE="${1}"
  19. PAGE_HTML="${2}"
  20. PAGE_CSS="${3}"
  21. PAGE_FAVICON="${4}"
  22. PAGE_CONTENT="$(pandoc --from markdown --to html ${5} | sed -e 's|/\">|/\" target=\"_blank\">|g; s|.png\">|.png\" target=\"_blank\">|g')"
  23. PAGE_CONTENT_FILE="${5}"
  24. DESTINATION_DIR="${6}"
  25. fi
  26. if [[ ! -z ${PAGE_TITLE} ]] && [[ ! -z ${PAGE_CONTENT} ]] && [[ ! -z ${PAGE_CONTENT_FILE} ]] && [[ ! -z ${DESTINATION_DIR} ]]; then
  27. if [[ ! -d "${DESTINATION_DIR}" ]]; then
  28. mkdir -p "${DESTINATION_DIR}"
  29. fi
  30. #PAGE_SEMIFINAL="$(cat ${PAGE_HTML} | sed -e "s|PAGE_TITLE|${PAGE_TITLE}|" | sed -e "s|PAGE_CSS|${PAGE_CSS}|" | sed -e "s|PAGE_FAVICON|${PAGE_FAVICON}|")"
  31. echo -e "<!-- ${PAGE_TITLE} -->\n<!-- ${PAGE_HTML} -->\n<!-- ${PAGE_CSS} -->\n<!-- ${PAGE_FAVICON} -->\n<!-- ${PAGE_CONTENT_FILE} -->\n\n$(cat ${PAGE_HTML} | sed -e "s|PAGE_TITLE|${PAGE_TITLE}|" | sed -e "s|PAGE_CSS|${PAGE_CSS}|" | sed -e "s|PAGE_FAVICON|${PAGE_FAVICON}|" | sed -e 's|\./|/|g')\n\t\t\t${PAGE_CONTENT}\n\t\t</main>\n\t</body>\n</html>" > "${DESTINATION_DIR}/index.html"
  32. else
  33. echo -e "USAGE:\n${0}\t[PAGE_TITLE]\t\t[PAGE_HTML (file)]\t[PAGE_CSS (file)]\n\t\t[PAGE_FAVICON (file)]\t[PAGE_CONTENT (file)]\t[DESTINATION_DIR]\n${0}\tregen\n${0}\t--regen\n${0}\tregen\t--continuous\n${0}\t--regen\t--continuous"
  34. fi
  35. export LAST_PAGE="${PAGE}"
  36. export HEAD="$(( ${HEAD} + 1 ))"
  37. if ([[ ${1} = 'regen' ]] || [[ ${1} = '--regen' ]]) && [[ ! "${LAST_PAGE}" = "${FINAL_PAGE}" ]]; then
  38. ${0} ${1}
  39. fi
  40. unset LAST_PAGE
  41. unset HEAD
  42. if [[ ${2} = '--continuous' ]]; then
  43. sleep 10
  44. ${0} ${1} ${2}
  45. fi