tex2html.sh 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. echo "* \"$u\":#$u" >> tmp/summary
  51. # right html and contents on main tmp/content.textile
  52. echo "<div id='$u' class='user'>" >> tmp/content.textile
  53. # add user content to main content
  54. echo "<section class='content'>"$'\n' >> tmp/content.textile
  55. # add content to main tmp/content.textile
  56. cat "$i/readme.textile" >> tmp/content.textile
  57. echo $'\n'"</section>" >> tmp/content.textile
  58. # get folder name
  59. folder=$(basename "$i")
  60. # _
  61. # (_)
  62. # _ _ __ ___ __ _ __ _ ___ ___
  63. # | | '_ ` _ \ / _` |/ _` |/ _ \/ __|
  64. # | | | | | | | (_| | (_| | __/\__ \
  65. # |_|_| |_| |_|\__,_|\__, |\___||___/
  66. # __/ |
  67. # |___/
  68. echo " images"
  69. images=""
  70. l=0
  71. echo "<section class='images'>"$'\n' >> tmp/content.textile
  72. for img in $i/images/*; do
  73. # echo "images : $img"
  74. if [ -f "$img" ] && [[ ! "$img" =~ ".db" ]] && [[ ! "$img" =~ ".avi" ]]; then
  75. # record file name
  76. fn=$(basename "$img")
  77. counter=$(printf %02d $l)
  78. # record extension
  79. ext="${fn##*.}"
  80. # record new image name
  81. fimg="$folder-$counter.$ext"
  82. # copy image file with new name
  83. cp -f "$img" ../output/images/$fimg
  84. # convert thumbs
  85. convert ../output/images/$fimg -resize 400x400\> ../output/thumbs/$fimg
  86. # replace image name in main tmp/content.textile file
  87. # pandoc can't render textile links
  88. sed -i "s/!images\/$fn!/<a data-lightbox='$folder' href='images\/$fimg'>!thumbs\/$fimg!<\/a>/g" tmp/content.textile
  89. # sed -i "s/!images\/$fn!/thumbs\/$fimg/g" tmp/content.textile
  90. # find "tmp/content.textile" -print0 | xargs -0 sed -i '' -e "s/images\/$fn/images\/$fimg/g"
  91. l=$(($l+1))
  92. # if image is not on content ...
  93. if [[ ! "$cont" =~ "images/$fn" ]]; then
  94. # ... add it at end of content
  95. echo "* <a data-lightbox='$folder' href='images/$fimg'>!thumbs/$fimg!</a>" >> tmp/content.textile
  96. fi
  97. fi
  98. done
  99. echo $'\n'"</section>" >> tmp/content.textile
  100. # _________ __ _______________ _____
  101. # / ___/ __ \/ / / / ___/ ___/ _ \/ ___/
  102. # (__ ) /_/ / /_/ / / / /__/ __(__ )
  103. # /____/\____/\__,_/_/ \___/\___/____/
  104. #
  105. echo " sources"
  106. echo "<section class='sources'>"$'\n' >> tmp/content.textile
  107. for src in $i/sources/*; do
  108. # echo "patch : $src"
  109. if [ -f "$src" ]; then
  110. # if ~ is not on file name ...
  111. if [[ ! "$src" =~ "~" ]]; then
  112. # record file name
  113. fn=$(basename "$src")
  114. cp -f "$src" ../output/sources/$fn
  115. # echo $'\r'"<li>" >> tmp/content.textile
  116. echo "* \"$fn\":sources/$fn" >> tmp/content.textile
  117. # echo $'\r'"</li>" >> tmp/content.textile
  118. fi
  119. fi
  120. done
  121. echo $'\n'"</section>" >> tmp/content.textile
  122. echo "</div>" >> tmp/content.textile
  123. echo '<div class="pagebreak"></div>' >> tmp/content.textile
  124. fi
  125. fi
  126. done
  127. # end main section
  128. echo "</section>" >> tmp/content.textile
  129. # _ _
  130. # | | | |
  131. # | |__ ___ __ _ __| | ___ _ __
  132. # | '_ \ / _ \/ _` |/ _` |/ _ \ '__|
  133. # | | | | __/ (_| | (_| | __/ |
  134. # |_| |_|\___|\__,_|\__,_|\___|_|
  135. echo "header"
  136. touch tmp/header
  137. echo "<header id='header'>"$'\n' > tmp/header
  138. echo "h1. OLA#3 Documentation"$'\n' >> tmp/header
  139. echo "<nav id='menu'>"$'\n' >> tmp/header
  140. cat tmp/summary >> tmp/header
  141. echo $'\n'"</nav>" >> tmp/header
  142. echo "</header>" >> tmp/header
  143. cat tmp/header|cat - tmp/content.textile > tmp/out && mv tmp/out tmp/content.textile
  144. echo "Pandoc"
  145. pandoc -s \
  146. -f textile \
  147. -t html5 -o ../output/index.html \
  148. -H style.tpl.html \
  149. -A script.tpl.html \
  150. tmp/content.textile
  151. # -H css/main.css \
  152. cp -r css ../output/
  153. cp -r fonts ../output/
  154. cp -r bower_components ../output/
  155. # echo "export markdown as html"
  156. # pandoc -s \
  157. # -f markdown+hard_line_breaks+auto_identifiers+ascii_identifiers+tex_math_dollars+pipe_tables+all_symbols_escapable \
  158. # -t html5 -o index.html \
  159. # -c fonts/amiri/amiri.css \
  160. # -H bower_components/lightbox2/dist/css/lightbox.min.css \
  161. # -H css/styles.css \
  162. # -B body-base-top.tpl.html \
  163. # -A body-base-bot.tpl.html \
  164. # -A js/jquery.min.js \
  165. # -A js/script.js \
  166. # # -A js/css-regions-polyfill.min.js \
  167. # -A body-base-end.tpl.html \
  168. # pad.md