publish.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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=
  24. if [ "${FILE}" != "./index" ]; then
  25. if [[ $FILE == *index ]]
  26. then
  27. DEST="../"
  28. else
  29. DEST="./"
  30. fi
  31. RETURN="<a href='$DEST'>Back to previous index</a>"
  32. OPTS="--css /headerleft.css -T Libreboot"
  33. fi
  34. if [ "${FILE}" != "./docs/fdl-1.3" ] && [ "${FILE}" != "./conduct" ]; then
  35. echo "" >> temp.md
  36. printf "[License](/docs/fdl-1.3.md) --\n" >> temp.md
  37. printf "[Template](/license.md) --\n" >> temp.md
  38. printf "[Authors](/contrib.md) --\n" >> temp.md
  39. printf "[Conduct Guidelines](/conduct.md) --\n" >> temp.md
  40. printf "[Management Guidelines](/management.md) --\n" >> temp.md
  41. printf "[Peers Community](https://peers.community/) \n" >> temp.md
  42. fi
  43. # change out .md -> .html
  44. sed temp.md -i -e 's/\.md\(#[a-z\-]*\)*)/.html\1)/g'
  45. sed temp.md -i -e 's/\.md\(#[a-z\-]*\)*]/.html\1]/g'
  46. # work around issue #2872
  47. TOC=$(grep -q "^x-toc-enable: true$" temp.md && echo "--toc --toc-depth=2") || TOC=""
  48. # work around heterogenous pandoc versions
  49. SMART=$(pandoc -v | grep -q '2\.0' || echo "--smart") || SMART=""
  50. # chuck through pandoc
  51. pandoc $TOC $SMART temp.md -s --css /global.css $OPTS \
  52. --template template.html --metadata return="$RETURN"> $FILE.html
  53. # additionally, produce bare file for RSS
  54. pandoc $1 > $FILE.bare.html
  55. # generate section title anchors as [link]
  56. 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>_'