publish.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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-z\-]*\)*)/.html\1)/g' "$TMPFILE"
  51. sed -i -e 's/\.md\(#[a-z\-]*\)*]/.html\1]/g' "$TMPFILE"
  52. # change out .md -> .html
  53. sed -i -e 's/\.md\(#[a-z\-]*\)*)/.html\1)/g' "$TMPFILE"
  54. sed -i -e 's/\.md\(#[a-z\-]*\)*]/.html\1]/g' "$TMPFILE"
  55. # work around issue #2872
  56. TOC=$(grep -q "^x-toc-enable: true$" "$TMPFILE" && printf '%s\n' "--toc --toc-depth=2") || TOC=""
  57. # work around heterogenous pandoc versions
  58. SMART=$(pandoc -v | grep -q '2\.0' || printf '%s\n' "--smart") || SMART=""
  59. # chuck through pandoc
  60. pandoc $TOC $SMART "$TMPFILE" -s --css /global.css $OPTS \
  61. --template template.html --metadata return="$RETURN"> $FILE.html
  62. # additionally, produce bare file for RSS
  63. pandoc $1 > $FILE.bare.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"