publish.sh 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. if [[ $FILE == "index" || $FILE == "./index" ]]; then
  26. TEMPLATE="template.homepage.html"
  27. OPTS="--css /headercenter.css"
  28. else
  29. if [[ $FILE == "news/rms" ]] || [[ $FILE == "./news/rms" ]]; then
  30. TEMPLATE="template.rms.html"
  31. else
  32. TEMPLATE="template.html"
  33. fi
  34. if [[ $FILE == *suppliers ]]
  35. then
  36. RETURN=""
  37. else
  38. if [[ $FILE == *index ]]
  39. then
  40. DEST="../"
  41. else
  42. DEST="./"
  43. fi
  44. RETURN=""
  45. OPTS="-T Libreboot"
  46. fi
  47. fi
  48. if [[ $FILE != "./docs/fdl-1.3" && $FILE != "docs/fdl-1.3" &&
  49. $FILE != "./conduct" && $FILE != "conduct" ]]; then
  50. cat footer.md >> "$TMPFILE"
  51. fi
  52. # change out .md -> .html
  53. sed -i -e 's/\.md\(#[a-zA-Z0-9_-]*\)\?\([])]*\)/.html\1\2/g' "$TMPFILE"
  54. # work around issue #2872
  55. TOC=$(grep -q "^x-toc-enable: true$" "$TMPFILE" && printf '%s\n' "--toc --toc-depth=2") || TOC=""
  56. # work around heterogenous pandoc versions
  57. SMART=$(pandoc -v | grep -q '2\.0' || printf '%s\n' "-f markdown+smart -t html") || SMART=""
  58. # chuck through pandoc
  59. #
  60. # $OPTS must not be quoted, otherwise pandoc interprets '--css /headercenter.css'
  61. # as one argument, when it is actually two.
  62. pandoc $TOC $SMART "$TMPFILE" -s --css /global.css $OPTS \
  63. --template ${TEMPLATE} --metadata return="$RETURN" > "$FILE.html"
  64. # generate section title anchors as [link]
  65. 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"
  66. # clean up temporary file
  67. rm -f "$TMPFILE"