publish.sh 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. ENGFILE=${FILE%.pt}
  23. TMPFILE=$(mktemp -t transit_www.XXXXXXXXXX)
  24. firstchar=$(head -c 1 ${1})
  25. if [[ "${firstchar}" == "%" ]]; then
  26. title="$(head -n1 ${1})"
  27. pagetext="$(tail -n+2 ${1})"
  28. else
  29. title="$(head -n4 ${1})"
  30. pagetext="$(tail -n+5 ${1})"
  31. fi
  32. langselect="[English](${ENGFILE}.md) -- [Português](${ENGFILE}.pt.md)"
  33. printf "%s\n" "${title}" > "$TMPFILE"
  34. if [[ $FILE != "./fdl-1.3" && $FILE != "fdl-1.3" &&
  35. $FILE != "./license" && $FILE != "license" ]]; then
  36. printf "\n%s\n" "${langselect}" >> "$TMPFILE"
  37. fi
  38. printf "\n%s\n" "${pagetext}" >> "$TMPFILE"
  39. OPTS="-T Transit"
  40. if [[ $ENGFILE == "index" || $ENGFILE == "./index" ]]; then
  41. OPTS="--css /headercenter.css"
  42. else
  43. if [[ $ENGFILE != $FILE ]]; then # portuguese
  44. if [[ $ENGFILE == *index ]]
  45. then
  46. DEST="../index.pt.html"
  47. else
  48. DEST="./index.pt.html"
  49. fi
  50. else # english
  51. if [[ $ENGFILE == *index ]]
  52. then
  53. DEST="../"
  54. else
  55. DEST="./"
  56. fi
  57. fi
  58. if [[ "$FILE" == "$ENGFILE" ]]; then
  59. RETURN="<strong><a href='/contrib.html#editing-the-website-and-documentation-wiki-style'>Edit this page</a></strong> -- <a href='$DEST'>Back to previous index</a>"
  60. OPTS="-T Transit"
  61. else
  62. RETURN="<strong><a href='/contrib.pt.html#editar-o-website-e-documentação-tal-como-se-tratasse-de-um-wiki'>Editar esta p&aacute;gina</a></strong> -- <a href='$DEST'>Voltar &agrave; p&aacute;gina anterior</a>"
  63. OPTS="-T Transit"
  64. fi
  65. fi
  66. if [[ "$FILE" != "${ENGFILE}" ]]; then # portuguese site
  67. if [[ $FILE != "./fdl-1.3" && $FILE != "fdl-1.3" &&
  68. $FILE != "./aup.pt" && $FILE != "aup.pt" ]]; then
  69. cat footer.pt.md >> "$TMPFILE"
  70. fi
  71. else
  72. if [[ $FILE != "./fdl-1.3" && $FILE != "fdl-1.3" &&
  73. $FILE != "./aup" && $FILE != "aup" ]]; then
  74. cat footer.md >> "$TMPFILE"
  75. fi
  76. fi
  77. # change out .md -> .html
  78. sed -i -e 's/\.md\(#[a-z\-]*\)*)/.html\1)/g' "$TMPFILE"
  79. sed -i -e 's/\.md\(#[a-z\-]*\)*]/.html\1]/g' "$TMPFILE"
  80. # change out .md -> .html
  81. sed -i -e 's/\.md\(#[a-z\-]*\)*)/.html\1)/g' "$TMPFILE"
  82. sed -i -e 's/\.md\(#[a-z\-]*\)*]/.html\1]/g' "$TMPFILE"
  83. # work around issue #2872
  84. TOC=$(grep -q "^x-toc-enable: true$" "$TMPFILE" && printf '%s\n' "--toc --toc-depth=2") || TOC=""
  85. # work around heterogenous pandoc versions
  86. SMART=$(pandoc -v | grep -q '2\.0' || printf '%s\n' "--smart") || SMART=""
  87. # chuck through pandoc
  88. #
  89. # $OPTS must not be quoted, otherwise pandoc interprets '--css /headercenter.css'
  90. # as one argument, when it is actually two.
  91. pandoc $TOC $SMART "$TMPFILE" -s --css /global.css $OPTS \
  92. --template template.html --metadata return="$RETURN" > "$FILE.html"
  93. # generate section title anchors as [link]
  94. 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"
  95. # clean up temporary filerm -f "$TMPFILE"