tex2html.sh 5.6 KB

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