build.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/bash
  2. set -e
  3. inputs="forgefed forgefed-vocabulary"
  4. git_branch=`git rev-parse --abbrev-ref HEAD`
  5. git_commit_id=`git rev-parse HEAD`
  6. git_commit_id_short=`git rev-parse --short HEAD`
  7. now=`date --utc +%Y-%m-%d`
  8. dirty () {
  9. git diff-index --quiet HEAD --
  10. }
  11. runPandoc () {
  12. local dir="$1"
  13. local file="$2"
  14. if [ "$3" == "true" ]; then
  15. local toc="--table-of-contents"
  16. else
  17. local toc=""
  18. fi
  19. local theme="$4"
  20. if [ "$theme" == "light" ]; then
  21. local otherTheme="/index/dark"
  22. local otherThemeName="🌑"
  23. local output="html/$file.html"
  24. local suffix=".html"
  25. else
  26. local otherTheme="/index"
  27. local otherThemeName="🌞"
  28. local output="html/$file/dark.html"
  29. local suffix="/dark.html"
  30. fi
  31. pandoc $dir/$file.md \
  32. --from markdown \
  33. --to html \
  34. --template html/template.html \
  35. $toc \
  36. --variable "gitbranch:$git_branch" \
  37. --variable "gitcommitid:$git_commit_id" \
  38. --variable "gitcommitidshort:$git_commit_id_short" \
  39. --variable "date:$now" \
  40. --variable "theme:$theme" \
  41. --variable "other-theme:$otherTheme" \
  42. --variable "other-theme-name:$otherThemeName" \
  43. --variable "suffix:$suffix" \
  44. --number-sections \
  45. --output "$output"
  46. #$gitdirty \
  47. }
  48. render () {
  49. local dir="$1"
  50. local file="$2"
  51. local toc="$3"
  52. runPandoc $dir $file $toc "light"
  53. runPandoc $dir $file $toc "dark"
  54. }
  55. #dirty
  56. #if [ $? -eq 0 ]; then
  57. # gitdirty=""
  58. #else
  59. # gitdirty="--variable gitdirty"
  60. #fi
  61. render html index "false"
  62. for file in $inputs; do
  63. render specification $file "true"
  64. done