tex2html.sh 4.8 KB

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