tex2html.sh 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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" ]; then # && [ "$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. # record file name
  93. fn=$(basename "$src")
  94. cp -f "$src" ../output/sources/$fn
  95. # echo $'\r'"<li>" >> content.textile
  96. echo "* \"$fn\":sources/$fn" >> content.textile
  97. # echo $'\r'"</li>" >> content.textile
  98. fi
  99. done
  100. echo $'\n'"</section>" >> content.textile
  101. echo "</div>" >> content.textile
  102. echo '<div class="pagebreak"></div>' >> content.textile
  103. fi
  104. fi
  105. done
  106. # end main section
  107. echo "</section>" >> content.textile
  108. # _ _
  109. # | | | |
  110. # | |__ ___ __ _ __| | ___ _ __
  111. # | '_ \ / _ \/ _` |/ _` |/ _ \ '__|
  112. # | | | | __/ (_| | (_| | __/ |
  113. # |_| |_|\___|\__,_|\__,_|\___|_|
  114. touch /tmp/header
  115. echo "<header id='header'>"$'\n' > /tmp/header
  116. echo "h1. OLA#3 Documentation"$'\n' >> /tmp/header
  117. echo "<nav id='menu'>"$'\n' >> /tmp/header
  118. cat /tmp/summary >> /tmp/header
  119. echo $'\n'"</nav>" >> /tmp/header
  120. echo "</header>" >> /tmp/header
  121. cat /tmp/header|cat - content.textile > /tmp/out && mv /tmp/out content.textile
  122. pandoc -s \
  123. -f textile \
  124. -t html5 -o ../output/index.html \
  125. -H css/main.css \
  126. -A script.tpl.html \
  127. content.textile
  128. # echo "export markdown as html"
  129. # pandoc -s \
  130. # -f markdown+hard_line_breaks+auto_identifiers+ascii_identifiers+tex_math_dollars+pipe_tables+all_symbols_escapable \
  131. # -t html5 -o index.html \
  132. # -c fonts/amiri/amiri.css \
  133. # -H css/styles.css \
  134. # -B body-base-top.tpl.html \
  135. # -A body-base-bot.tpl.html \
  136. # -A js/jquery.min.js \
  137. # -A js/script.js \
  138. # # -A js/css-regions-polyfill.min.js \
  139. # -A body-base-end.tpl.html \
  140. # pad.md