my website https://sn0w.sh
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.

build.sh 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/bash
  2. set -e
  3. set -o pipefail
  4. shopt -s globstar
  5. #
  6. # Render markdown to html
  7. #
  8. render() { # 1: md source, # 2: html target
  9. echo "#>> Rendering ${1} as ${2}"
  10. cat ./partials/header.html > "${2}"
  11. pandoc \
  12. -f gfm-smart \
  13. -t html5 \
  14. "${1}" >> "${2}"
  15. cat ./partials/footer.html >> "${2}"
  16. }
  17. #
  18. # Render markdown with header and footer
  19. #
  20. render_type() { # 1: type, 2: md source, 3: html target
  21. cat ./partials/${1}_header.md >> "${2}_tmp"
  22. cat "${2}" >> "${2}_tmp"
  23. cat ./partials/${1}_footer.md >> "${2}_tmp"
  24. render "${2}_tmp" "${3}"
  25. rm "${2}_tmp"
  26. }
  27. #
  28. # Drop last build
  29. #
  30. echo "#> Cleaning up"
  31. if [[ -d _public ]]; then
  32. rm -r _public
  33. fi
  34. mkdir -p _public/blog
  35. #
  36. # Build pages
  37. #
  38. echo "#> Making pages/posts"
  39. for page in ./content/**/*.md; do
  40. file="$(echo "${page}" | rev | cut -d/ -f1 | rev | sed 's/\.md//g').html"
  41. if [[ "${page}" =~ "blog" ]]; then
  42. render_type blog_post "${page}" "./_public/blog/${file}"
  43. else
  44. render_type page "${page}" "./_public/${file}"
  45. fi
  46. done
  47. #
  48. # Build blog index
  49. #
  50. echo "#> Making blog index"
  51. cat ./partials/blog_index_header.md >> ./_public/blog/index.md
  52. for page in $(ls ./content/blog/*.md | sort -d -r); do
  53. file="$(echo "${page}" | rev | cut -d/ -f1 | rev | sed 's/\.md//g')"
  54. title="$(echo "${file}" | cut -d_ -f2- | sed 's/-/ /g')"
  55. date="$(echo "${file}" | cut -d_ -f1)"
  56. echo "#>> Adding ${title} from ${date}"
  57. echo "|![](/assets/icons/file.gif)|[${title}.txt](/blog/${file}.html)|${date}|$(wc -w ${page} | cut -d' ' -f1)" >> ./_public/blog/index.md
  58. done
  59. cat ./partials/blog_index_footer.md >> ./_public/blog/index.md
  60. render ./_public/blog/index.md ./_public/blog/index.html
  61. rm ./_public/blog/index.md
  62. #
  63. # Copy media
  64. #
  65. echo "#> Transferring media"
  66. cp -r assets _public/assets
  67. #
  68. # Post-build actions
  69. #
  70. if [[ "$1" == "--serve" || "$1" == "--server" || "$1" == "--preview" || "$1" == "-s" ]]; then
  71. php -t _public -S localhost:8080
  72. exit 0
  73. fi
  74. if [[ "$1" == "--push" || "$1" == "-p" ]]; then
  75. echo "#> Pushing..."
  76. source .env
  77. neocities push ./_public
  78. exit 0
  79. fi