tex2html.sh 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. #!/bin/bash
  2. # 06-07-2016
  3. # Licence : GPLv3
  4. echo "generating complete file"
  5. echo "creating folders"
  6. if [ ! -d ../output/images ]; then
  7. mkdir ../output/images
  8. fi
  9. if [ ! -d ../output/thumbs ]; then
  10. mkdir ../output/thumbs
  11. fi
  12. if [ ! -d ../output/sources ]; then
  13. mkdir ../output/sources
  14. fi
  15. # if [ -f content.textile ]; then
  16. # rm content.textile
  17. # fi
  18. if [ ! -d temp ]; then
  19. rm -rf tmp
  20. fi
  21. mkdir tmp
  22. touch tmp/content.textile
  23. touch tmp/summary
  24. # echo "" > tmp/summary
  25. echo "reading content"
  26. # _ _
  27. # | | | |
  28. # ___ ___ _ __ | |_ ___ _ __ | |_
  29. # / __/ _ \| '_ \| __/ _ \ '_ \| __|
  30. # | (_| (_) | | | | || __/ | | | |_
  31. # \___\___/|_| |_|\__\___|_| |_|\__|
  32. echo "<section id='main'>" >> tmp/content.textile
  33. for i in ../content/*; do
  34. # if folder if not sys if not modele
  35. if [ -d "$i" ] && [[ ! "$i" =~ "model" ]]; then
  36. # if readme exists
  37. if [ -f "$i/readme.textile" ]; then
  38. # user name
  39. # record readme content on variable
  40. cont=$(cat "$i/readme.textile")
  41. echo "$i"
  42. # echo "$cont"
  43. # user=$(grep "h1\.\s*.+" "$i/readme.textile")
  44. # user="${cont% h1}"
  45. # user=$(expr "$cont" : "h1. \(.*\)$")
  46. # echo "user : $user"
  47. u=${i/..\//}
  48. # record link for menu
  49. # echo "<li><a href='#$u'>$u</a></li>" >> tmp/summary
  50. u=${u/content//}
  51. id=${u:2}
  52. echo "* \"$id\":#$id" >> tmp/summary
  53. # right html and contents on main tmp/content.textile
  54. echo "<div id='$id' class='user'>" >> tmp/content.textile
  55. # add user content to main content
  56. echo "<section class='content'>"$'\n' >> tmp/content.textile
  57. # add content to main tmp/content.textile
  58. cat "$i/readme.textile" >> tmp/content.textile
  59. echo $'\n'"</section>" >> tmp/content.textile
  60. # get folder name
  61. folder=$(basename "$i")
  62. # _
  63. # (_)
  64. # _ _ __ ___ __ _ __ _ ___ ___
  65. # | | '_ ` _ \ / _` |/ _` |/ _ \/ __|
  66. # | | | | | | | (_| | (_| | __/\__ \
  67. # |_|_| |_| |_|\__,_|\__, |\___||___/
  68. # __/ |
  69. # |___/
  70. echo " images"
  71. images=""
  72. l=0
  73. echo "<section class='images'>"$'\n' >> tmp/content.textile
  74. for img in $i/images/*; do
  75. # echo "images : $img"
  76. if [ -f "$img" ] && [[ ! "$img" =~ ".db" ]] && [[ ! "$img" =~ ".avi" ]]; then
  77. # record file name
  78. fn=$(basename "$img")
  79. counter=$(printf %02d $l)
  80. # record extension
  81. ext="${fn##*.}"
  82. # record new image name
  83. fimg="$folder-$counter.$ext"
  84. # copy image file with new name
  85. cp -f "$img" ../output/images/$fimg
  86. # convert thumbs
  87. convert ../output/images/$fimg -resize 800x800\> ../output/thumbs/$fimg
  88. # replace image name in main tmp/content.textile file
  89. # pandoc can't render textile links
  90. sed -i \
  91. "s/!images\/$fn!/<a data-lightbox='$folder' href='images\/$fimg'>!thumbs\/$fimg!<\/a>/g" tmp/content.textile
  92. # sed -i "s/!images\/$fn!/thumbs\/$fimg/g" tmp/content.textile
  93. # find "tmp/content.textile" -print0 | xargs -0 sed -i '' -e "s/images\/$fn/images\/$fimg/g"
  94. l=$(($l+1))
  95. # if image is not on content ...
  96. if [[ ! "$cont" =~ "images/$fn" ]]; then
  97. # ... add it at end of content
  98. echo "* <a data-lightbox='$folder' href='images/$fimg'>!thumbs/$fimg!</a>" >> tmp/content.textile
  99. fi
  100. fi
  101. done
  102. echo $'\n'"</section>" >> tmp/content.textile
  103. # _________ __ _______________ _____
  104. # / ___/ __ \/ / / / ___/ ___/ _ \/ ___/
  105. # (__ ) /_/ / /_/ / / / /__/ __(__ )
  106. # /____/\____/\__,_/_/ \___/\___/____/
  107. #
  108. echo " sources"
  109. echo "<section class='sources'>"$'\n' >> tmp/content.textile
  110. for src in $i/sources/*; do
  111. # echo "patch : $src"
  112. if [ -f "$src" ]; then
  113. # if ~ is not on file name ...
  114. if [[ ! "$src" =~ "~" ]]; then
  115. # record file name
  116. fn=$(basename "$src")
  117. cp -f "$src" ../output/sources/$i/$fn
  118. # echo $'\r'"<li>" >> tmp/content.textile
  119. echo "* \"$fn\":sources/$i/$fn" >> tmp/content.textile
  120. # echo $'\r'"</li>" >> tmp/content.textile
  121. fi
  122. fi
  123. done
  124. echo $'\n'"</section>" >> tmp/content.textile
  125. echo "</div>" >> tmp/content.textile
  126. echo '<div class="pagebreak"></div>' >> tmp/content.textile
  127. fi
  128. fi
  129. done
  130. # ____ __
  131. # / __ \____ _____/ /
  132. # / /_/ / __ `/ __ /
  133. # / ____/ /_/ / /_/ /
  134. # /_/ \__,_/\__,_/
  135. # curl http://pads.osp.kitchen/p/ola-workshop/export/txt -o tmp/pad.md
  136. curl https://mypads.framapad.org/p/ola-5doc-6117z7kl/export/txt -o tmp/pad.md
  137. echo "* \"Pad\":#pad" >> tmp/summary
  138. # right html and contents on main tmp/content.textile
  139. echo "<div id='pad' class='user'>" >> tmp/content.textile
  140. echo "<h1>Pad</h1>" >> tmp/content.textile
  141. # add user content to main content
  142. echo "<section class='content'>"$'\n' >> tmp/content.textile
  143. # add content to main tmp/content.textile
  144. pandoc -f markdown -t textile -o tmp/pad.textile tmp/pad.md
  145. cat tmp/pad.textile >> tmp/content.textile
  146. echo $'\n'"</section>" >> tmp/content.textile
  147. echo "</div>" >> tmp/content.textile
  148. echo '<div class="pagebreak"></div>' >> tmp/content.textile
  149. # ______ __ ____ __
  150. # / ____/___ ____ / /__/ __ )____ ____ / /__
  151. # / / / __ \/ __ \/ //_/ __ / __ \/ __ \/ //_/
  152. # / /___/ /_/ / /_/ / ,< / /_/ / /_/ / /_/ / ,<
  153. # \____/\____/\____/_/|_/_____/\____/\____/_/|_|
  154. # curl http://pads.osp.kitchen/p/ola-cookbook/export/txt -o tmp/cookbook.md
  155. #
  156. # echo "* \"CookBook\":#cookbook" >> tmp/summary
  157. #
  158. # # right html and contents on main tmp/content.textile
  159. # echo "<div id='cookbook' class='user'>" >> tmp/content.textile
  160. # echo "<h1>CookBook</h1>" >> tmp/content.textile
  161. # # add user content to main content
  162. # echo "<section class='content'>"$'\n' >> tmp/content.textile
  163. # # add content to main tmp/content.textile
  164. # pandoc -f markdown -t textile -o tmp/cookbook.textile tmp/cookbook.md
  165. # cat tmp/cookbook.textile >> tmp/content.textile
  166. # echo $'\n'"</section>" >> tmp/content.textile
  167. # echo "</div>" >> tmp/content.textile
  168. #
  169. # echo '<div class="pagebreak"></div>' >> tmp/content.textile
  170. # end main section
  171. echo "</section>" >> tmp/content.textile
  172. # _ _
  173. # | | | |
  174. # | |__ ___ __ _ __| | ___ _ __
  175. # | '_ \ / _ \/ _` |/ _` |/ _ \ '__|
  176. # | | | | __/ (_| | (_| | __/ |
  177. # |_| |_|\___|\__,_|\__,_|\___|_|
  178. echo "header"
  179. touch tmp/header
  180. echo "<header id='header'>"$'\n' > tmp/header
  181. echo "h1. OLA#5 Documentation : An Mertens, Programation Python Algolittéraire"$'\n' >> tmp/header
  182. echo "<nav id='menu'>"$'\n' >> tmp/header
  183. cat tmp/summary >> tmp/header
  184. echo $'\n'"</nav>" >> tmp/header
  185. echo "</header>" >> tmp/header
  186. cat tmp/header|cat - tmp/content.textile > tmp/out && mv tmp/out tmp/content.textile
  187. echo "Pandoc"
  188. pandoc -s \
  189. -f textile \
  190. -t html5 -o ../output/index.html \
  191. -H style.tpl.html \
  192. -A script.tpl.html \
  193. tmp/content.textile
  194. # -H css/main.css \
  195. cp -r css ../output/
  196. cp -r fonts ../output/
  197. cp -r bower_components ../output/
  198. # echo "export markdown as html"
  199. # pandoc -s \
  200. # -f markdown+hard_line_breaks+auto_identifiers+ascii_identifiers+tex_math_dollars+pipe_tables+all_symbols_escapable \
  201. # -t html5 -o index.html \
  202. # -c fonts/amiri/amiri.css \
  203. # -H bower_components/lightbox2/dist/css/lightbox.min.css \
  204. # -H css/styles.css \
  205. # -B body-base-top.tpl.html \
  206. # -A body-base-bot.tpl.html \
  207. # -A js/jquery.min.js \
  208. # -A js/script.js \
  209. # # -A js/css-regions-polyfill.min.js \
  210. # -A body-base-end.tpl.html \
  211. # pad.md