publish.sh 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/bash
  2. #
  3. # Copyright (C) 2017 Alyssa Rosenzweig <alyssa@rosenzweig.io>
  4. # Copyright (C) 2017 Leah Rowe <info@minifree.org>
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. [ "x${DEBUG+set}" = 'xset' ] && set -v
  19. set -e
  20. echo $1
  21. FILE=${1%.md}
  22. cat $1 > temp.md
  23. OPTS="-T Libreboot"
  24. if [ "${FILE}" != "./index" ]; then
  25. if [[ $FILE == *suppliers ]]
  26. then
  27. RETURN=""
  28. else
  29. if [[ $FILE == *index ]]
  30. then
  31. DEST="../"
  32. else
  33. DEST="./"
  34. fi
  35. 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>"
  36. OPTS="-T Libreboot"
  37. fi
  38. else
  39. OPTS="--css /headercenter.css"
  40. fi
  41. if [[ $FILE = *suppliers ]]; then
  42. printf "\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>\n" >> temp.md
  43. fi
  44. if [ "${FILE}" != "./docs/fdl-1.3" ] && [ "${FILE}" != "./conduct" ]; then
  45. cat footer.md >> temp.md
  46. fi
  47. # change out .md -> .html
  48. sed temp.md -i -e 's/\.md\(#[a-z\-]*\)*)/.html\1)/g'
  49. sed temp.md -i -e 's/\.md\(#[a-z\-]*\)*]/.html\1]/g'
  50. # change out .md -> .html
  51. sed temp.md -i -e 's/\.md\(#[a-z\-]*\)*)/.html\1)/g'
  52. sed temp.md -i -e 's/\.md\(#[a-z\-]*\)*]/.html\1]/g'
  53. # work around issue #2872
  54. TOC=$(grep -q "^x-toc-enable: true$" temp.md && echo "--toc --toc-depth=2") || TOC=""
  55. # work around heterogenous pandoc versions
  56. SMART=$(pandoc -v | grep -q '2\.0' || echo "--smart") || SMART=""
  57. # chuck through pandoc
  58. pandoc $TOC $SMART temp.md -s --css /global.css $OPTS \
  59. --template template.html --metadata return="$RETURN"> $FILE.html
  60. # additionally, produce bare file for RSS
  61. pandoc $1 > $FILE.bare.html
  62. # generate section title anchors as [link]
  63. sed $FILE.html -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>_'