publish.sh 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (C) 2017 Alyssa Rosenzweig <alyssa@rosenzweig.io>
  4. # Copyright (C) 2017 Leah Rowe <info@minifree.org>
  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. OPTS="--css /headercenter.css"
  27. else
  28. if [[ $FILE == *suppliers ]]
  29. then
  30. RETURN=""
  31. else
  32. if [[ $FILE == *index ]]
  33. then
  34. DEST="../"
  35. else
  36. DEST="./"
  37. fi
  38. RETURN="<strong><a href='/git.html#editing-the-website-and-documentation-wiki-style'>Edit this page</a></strong> -- <a href='$DEST'>Back to previous index</a>"
  39. OPTS="-T Libreboot"
  40. fi
  41. fi
  42. if [[ $FILE = *suppliers ]]; then
  43. printf '\n%s\n' "<strong><a href=\"/git.html#editing-the-website-and-documentation-wiki-style\">Edit this page</a></strong> -- <a href=\"../\">Back to previous page</a>" >> "$TMPFILE"
  44. fi
  45. if [[ $FILE != "./docs/fdl-1.3" && $FILE != "docs/fdl-1.3" &&
  46. $FILE != "./conduct" && $FILE != "conduct" ]]; then
  47. cat footer.md >> "$TMPFILE"
  48. fi
  49. # change out .md -> .html
  50. sed -i -e 's/\.md\(#[a-zA-Z0-9_-]*\)\?\([])]*\)/.html\1\2/g' "$TMPFILE"
  51. # work around issue #2872
  52. TOC=$(grep -q "^x-toc-enable: true$" "$TMPFILE" && printf '%s\n' "--toc --toc-depth=2") || TOC=""
  53. # work around heterogenous pandoc versions
  54. SMART=$(pandoc -v | grep -q '2\.0' || printf '%s\n' "--smart") || SMART=""
  55. # chuck through pandoc
  56. #
  57. # $OPTS must not be quoted, otherwise pandoc interprets '--css /headercenter.css'
  58. # as one argument, when it is actually two.
  59. pandoc $TOC $SMART "$TMPFILE" -s --css /global.css $OPTS \
  60. --template template.html --metadata return="$RETURN" > "$FILE.html"
  61. # generate section title anchors as [link]
  62. 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"
  63. # clean up temporary file
  64. rm -f "$TMPFILE"