publish.sh 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (C) 2017,2021 Leah Rowe <info@minifree.org>
  4. # Copyright (C) 2017 Alyssa Rosenzweig <alyssa@rosenzweig.io>
  5. # Copyright (C) 2017 Michael Reed <michael@michaelreed.io>
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. [ "x${DEBUG+set}" = 'xset' ] && set -v
  20. set -e
  21. FILE=${1%.md}
  22. TMPFILE=$(mktemp -t libreboot_www.XXXXXXXXXX)
  23. cat "$1" > "$TMPFILE"
  24. OPTS="-T Libreboot"
  25. LANG="${FILE##*.}"
  26. if [ "${LANG}" = "${FILE}" ]; then
  27. LANG="en"
  28. else
  29. FILE="${FILE%.*}"
  30. fi
  31. if [[ $FILE == "index" || $FILE == "./index" ]]; then
  32. TEMPLATE="template.homepage.html"
  33. OPTS="--css /headercenter.css"
  34. else
  35. if [[ $FILE == "news/rms" ]] || [[ $FILE == "./news/rms" ]]; then
  36. TEMPLATE="template.rms.html"
  37. else
  38. TEMPLATE="template.html"
  39. fi
  40. if [[ $FILE == *suppliers ]]
  41. then
  42. RETURN=""
  43. else
  44. if [[ $FILE == *index ]]
  45. then
  46. DEST="../"
  47. else
  48. DEST="./"
  49. fi
  50. RETURN=""
  51. OPTS="-T Libreboot"
  52. fi
  53. fi
  54. if [ "${LANG}" != "en" ]; then
  55. FILE="${FILE}.${LANG}"
  56. fi
  57. if [[ $FILE != "./docs/fdl-1.3" && $FILE != "docs/fdl-1.3" &&
  58. $FILE != "./conduct" && $FILE != "conduct" ]]; then
  59. cat footer.md >> "$TMPFILE"
  60. fi
  61. # change out .md -> .html
  62. sed -i -e 's/\.md\(#[a-zA-Z0-9_-]*\)\?\([])]*\)/.html\1\2/g' "$TMPFILE"
  63. # work around issue #2872
  64. TOC=$(grep -q "^x-toc-enable: true$" "$TMPFILE" && printf '%s\n' "--toc --toc-depth=2") || TOC=""
  65. if [ "${TEMPLATE}" = "template.rms.html" ]; then
  66. TOC=$(printf '%s\n' "--toc --toc-depth=2")
  67. fi
  68. # work around heterogenous pandoc versions
  69. SMART=$(pandoc -v | grep -q '2\.0' || printf '%s\n' "-f markdown+smart -t html") || SMART=""
  70. # chuck through pandoc
  71. #
  72. # $OPTS must not be quoted, otherwise pandoc interprets '--css /headercenter.css'
  73. # as one argument, when it is actually two.
  74. pandoc -V lang=${LANG} $TOC $SMART "$TMPFILE" -s --css /global.css $OPTS \
  75. --template ${TEMPLATE} --metadata return="$RETURN" > "$FILE.html"
  76. # generate section title anchors as [link]
  77. sed -i -e 's_^<h\([123]\) id="\(.*\)">\(.*\)</h\1>_<div class="h"><h\1 id="\2">\3</h\1><a aria-hidden="true" href="#\2">[link]</a></div>_' "$FILE.html"
  78. if [ "${LANG}" = "ar" ] || [ "${LANG}" = "he" ]; then
  79. sed -i -e 's/html\ lang/html dir=\"rtl\"\ lang/' "$FILE.html"
  80. fi
  81. # clean up temporary file
  82. rm -f "$TMPFILE"