tex2html.sh 5.5 KB

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