tex2html.sh 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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/$fn
  118. # echo $'\r'"<li>" >> tmp/content.textile
  119. echo "* \"$fn\":sources/$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. echo "* \"Pad\":#pad" >> tmp/summary
  137. # right html and contents on main tmp/content.textile
  138. echo "<div id='pad' class='user'>" >> tmp/content.textile
  139. echo "<h1>Pad</h1>" >> tmp/content.textile
  140. # add user content to main content
  141. echo "<section class='content'>"$'\n' >> tmp/content.textile
  142. # add content to main tmp/content.textile
  143. pandoc -f markdown -t textile -o tmp/pad.textile tmp/pad.md
  144. cat tmp/pad.textile >> tmp/content.textile
  145. echo $'\n'"</section>" >> tmp/content.textile
  146. echo "</div>" >> tmp/content.textile
  147. echo '<div class="pagebreak"></div>' >> tmp/content.textile
  148. # ______ __ ____ __
  149. # / ____/___ ____ / /__/ __ )____ ____ / /__
  150. # / / / __ \/ __ \/ //_/ __ / __ \/ __ \/ //_/
  151. # / /___/ /_/ / /_/ / ,< / /_/ / /_/ / /_/ / ,<
  152. # \____/\____/\____/_/|_/_____/\____/\____/_/|_|
  153. curl http://pads.osp.kitchen/p/ola-cookbook/export/txt -o tmp/cookbook.md
  154. echo "* \"CookBook\":#cookbook" >> tmp/summary
  155. # right html and contents on main tmp/content.textile
  156. echo "<div id='cookbook' class='user'>" >> tmp/content.textile
  157. echo "<h1>CookBook</h1>" >> tmp/content.textile
  158. # add user content to main content
  159. echo "<section class='content'>"$'\n' >> tmp/content.textile
  160. # add content to main tmp/content.textile
  161. pandoc -f markdown -t textile -o tmp/cookbook.textile tmp/cookbook.md
  162. cat tmp/cookbook.textile >> tmp/content.textile
  163. echo $'\n'"</section>" >> tmp/content.textile
  164. echo "</div>" >> tmp/content.textile
  165. echo '<div class="pagebreak"></div>' >> tmp/content.textile
  166. # end main section
  167. echo "</section>" >> tmp/content.textile
  168. # _ _
  169. # | | | |
  170. # | |__ ___ __ _ __| | ___ _ __
  171. # | '_ \ / _ \/ _` |/ _` |/ _ \ '__|
  172. # | | | | __/ (_| | (_| | __/ |
  173. # |_| |_|\___|\__,_|\__,_|\___|_|
  174. echo "header"
  175. touch tmp/header
  176. echo "<header id='header'>"$'\n' > tmp/header
  177. echo "h1. OLA#4 Documentation : OSP html2print"$'\n' >> tmp/header
  178. echo "<nav id='menu'>"$'\n' >> tmp/header
  179. cat tmp/summary >> tmp/header
  180. echo $'\n'"</nav>" >> tmp/header
  181. echo "</header>" >> tmp/header
  182. cat tmp/header|cat - tmp/content.textile > tmp/out && mv tmp/out tmp/content.textile
  183. echo "Pandoc"
  184. pandoc -s \
  185. -f textile \
  186. -t html5 -o ../output/index.html \
  187. -H style.tpl.html \
  188. -A script.tpl.html \
  189. tmp/content.textile
  190. # -H css/main.css \
  191. cp -r css ../output/
  192. cp -r fonts ../output/
  193. cp -r bower_components ../output/
  194. # echo "export markdown as html"
  195. # pandoc -s \
  196. # -f markdown+hard_line_breaks+auto_identifiers+ascii_identifiers+tex_math_dollars+pipe_tables+all_symbols_escapable \
  197. # -t html5 -o index.html \
  198. # -c fonts/amiri/amiri.css \
  199. # -H bower_components/lightbox2/dist/css/lightbox.min.css \
  200. # -H css/styles.css \
  201. # -B body-base-top.tpl.html \
  202. # -A body-base-bot.tpl.html \
  203. # -A js/jquery.min.js \
  204. # -A js/script.js \
  205. # # -A js/css-regions-polyfill.min.js \
  206. # -A body-base-end.tpl.html \
  207. # pad.md