publish.sh 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. # for link to the live editor
  23. editlink="${FILE/.\//.\/docs\/}.md"
  24. editlink="${editlink/.\/docs\/docs/docs}"
  25. editlink="${editlink/.\/docs/www}EDIT"
  26. cat $1 > temp.md
  27. OPTS="-T Libreboot"
  28. if [ "${FILE}" != "./index" ]; then
  29. if [[ $FILE == *suppliers ]]
  30. then
  31. RETURN=""
  32. else
  33. if [[ $FILE == *index ]]
  34. then
  35. DEST="../"
  36. else
  37. DEST="./"
  38. fi
  39. RETURN="<strong><a href='https://notabug.org/libreboot/libreboot/_edit/master/${editlink}'>Edit this page</a></strong> -- <a href='$DEST'>Back to previous index</a>"
  40. OPTS="-T Libreboot"
  41. fi
  42. else
  43. OPTS="--css /headercenter.css"
  44. fi
  45. if [[ $FILE = *suppliers ]]; then
  46. printf "\n<strong><a href=\"https://notabug.org/libreboot/libreboot/_edit/master/${editlink}\">Edit this page</a></strong> -- <a href=\"../\">Back to previous page</a>\n" >> temp.md
  47. fi
  48. if [ "${FILE}" != "./docs/fdl-1.3" ] && [ "${FILE}" != "./conduct" ]; then
  49. printf "\n\n**[Edit this page](https://notabug.org/libreboot/libreboot/_edit/master/%s)** --\n" "${editlink}" >> temp.md
  50. cat footer.md >> temp.md
  51. fi
  52. # change out .md -> .html
  53. sed temp.md -i -e 's/\.md\(#[a-z\-]*\)*)/.html\1)/g'
  54. sed temp.md -i -e 's/\.md\(#[a-z\-]*\)*]/.html\1]/g'
  55. # change out .md -> .html
  56. sed temp.md -i -e 's/\.md\(#[a-z\-]*\)*)/.html\1)/g'
  57. sed temp.md -i -e 's/\.md\(#[a-z\-]*\)*]/.html\1]/g'
  58. # work around issue #2872
  59. TOC=$(grep -q "^x-toc-enable: true$" temp.md && echo "--toc --toc-depth=2") || TOC=""
  60. # work around heterogenous pandoc versions
  61. SMART=$(pandoc -v | grep -q '2\.0' || echo "--smart") || SMART=""
  62. # chuck through pandoc
  63. pandoc $TOC $SMART temp.md -s --css /global.css $OPTS \
  64. --template template.html --metadata return="$RETURN"> $FILE.html
  65. # additionally, produce bare file for RSS
  66. pandoc $1 > $FILE.bare.html
  67. # generate section title anchors as [link]
  68. 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>_'
  69. sed -i -e 's/mdEDIT/md/g' $FILE.html