makeweb.sh 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. #!/usr/bin/env sh
  2. #
  3. ###############################################################
  4. #
  5. # This is Gridfinity makeweb (Release 202101030B) [GFODLv1]
  6. #
  7. ###############################################################
  8. #
  9. # The Gridfinity Open Documentation License v1.0 (GFODLv1)
  10. #
  11. # Copyright © 2021 Jeffrey H. Johnson. <trnsz@pobox.com>
  12. # Copyright © 2021 Gridfinity, LLC. <admin@gridfinity.com>
  13. #
  14. # All Rights Reserved.
  15. #
  16. # Redistribution and use, in source and compiled forms,
  17. # with or without modification, are permitted, provided
  18. # that the following conditions are met:
  19. #
  20. # 1. Redistributions of source code must retain the
  21. # above copyright notice, this list of conditions,
  22. # and the following disclaimer, within the first
  23. # ten lines of this file, completely unmodified.
  24. #
  25. # 2. Redistributions in compiled form must reproduce
  26. # the above copyright notice, this list of conditions,
  27. # and the following disclaimer in the documentation,
  28. # and/or other materials provided with the distribution.
  29. #
  30. # THIS DOCUMENTATION IS PROVIDED BY THE AUTHORS "AS IS",
  31. # AND ANY WARRANTIES, EXPRESS OR IMPLIED, INCLUDING, BUT
  32. # NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  33. # AND FITNESS FOR ANY PARTICULAR PURPOSE ARE DISCLAIMED.
  34. # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT,
  35. # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  36. # DAMAGES, INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  37. # SUBSTITUTE GOODS OR SERVICES, LOSS OF USE, DATA, OR PROFITS,
  38. # OR BUSINESS INTERRUPTION, HOWEVER CAUSED, AND ON ANY
  39. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  40. # OR TORT, INCLUDING NEGLIGENCE OR OTHERWISE, ARISING IN
  41. # ANY WAY OUT OF THE USE OF THIS DOCUMENTATION, EVEN IF
  42. # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  43. #
  44. ###############################################################
  45. # makeweb 202101030B requires: POSIX sh, semver-tool >=3.2.0,
  46. # fixjson >=1.1.0, vangen >=20201119, sponge >=20060219,
  47. # Tidy-HTML5 >=5.7.28, GNU find, GNU xargs, GNU sed, recent Git
  48. ###############################################################
  49. #
  50. set -u ||
  51. true
  52. :
  53. set -e ||
  54. true
  55. :
  56. if [ ! -f "./modules.json" ]; then
  57. printf '%s\n' \
  58. "Error: modules.json not found" \
  59. >&2
  60. exit 1
  61. fi
  62. printf '%s ' \
  63. "Cleaning JSON..."
  64. fixjson -w -i 1 modules.json \
  65. >/dev/null \
  66. 2>&1 ||
  67. {
  68. printf '%s\n' \
  69. "Error: fixjson failed" \
  70. >&2
  71. exit 1
  72. }
  73. printf '%s\n' \
  74. "ok" ||
  75. true
  76. :
  77. printf '%s ' \
  78. "Running vangen..."
  79. "${GOBIN:?}/vangen" \
  80. -config "./modules.json" \
  81. -out "./public" \
  82. >/dev/null \
  83. 2>&1 ||
  84. {
  85. printf '%s\n' \
  86. "Error: vangen failed" \
  87. >&2
  88. exit 1
  89. }
  90. printf '%s\n' \
  91. "ok" ||
  92. true
  93. :
  94. printf '%s ' \
  95. "Debranding index..." ||
  96. true
  97. :
  98. grep -iav \
  99. '^Generated by .*vangen.*.$' \
  100. public/index.html \
  101. 2>/dev/null |
  102. sed -e 's/ Go Modules//' |
  103. grep -iav 'Tools:' |
  104. grep -iav 'Libraries:' |
  105. sponge public/index.html \
  106. 2>/dev/null \
  107. 1>&2 ||
  108. {
  109. printf '%s\n' \
  110. "Error: debranding failed" \
  111. >&2
  112. exit 1
  113. }
  114. printf '%s\n' \
  115. "ok" ||
  116. true
  117. :
  118. printf '%s ' \
  119. "Cleaning HTML..." ||
  120. true
  121. :
  122. find "./public" -name '*.html' -exec \
  123. tidy --add-meta-charset true -utf8 -w 0 -qiubnm \
  124. "{}" \; \
  125. 2>/dev/null \
  126. >/dev/null \
  127. 2>&1 ||
  128. {
  129. printf '%s\n' \
  130. "Error: cleaning failed" \
  131. >&2
  132. exit 1
  133. }
  134. printf '%s\n' \
  135. "ok" ||
  136. true
  137. :
  138. printf '%s ' \
  139. "Transforming HTML..." ||
  140. true
  141. :
  142. find ./public -name '*.html' -print0 \
  143. 2>/dev/null |
  144. xargs -0 -L1 -I{} \
  145. sh -c \
  146. 'grep -iav ".*generator.*HTML.*Tidy.*>$" "{}" 2>/dev/null |
  147. sed -e "s/<HR>//" |
  148. sed -e "s/\"\//\"/" |
  149. sed -e "s/display: inline-block;/text-align: center; display: inline-block;/" |
  150. sed -e "s/<STYLE>/<STYLE>\n .center-screen { display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; min-height: 100vh; }/" |
  151. sed -e "s/<DIV class=\"content\">/<DIV class=\"center-screen\">/" |
  152. sed -e "s/Home: /<SMALL>Docs: /" |
  153. sed -e "s/Source: /Repo: /" |
  154. sed -e "s/<UL>//" -e "s/<LI>//" -e "s/<\/UL>//" -e "s/<\/LI>/<\/SMALL>/" |
  155. grep -v "^ \+$" |
  156. tidy --add-meta-charset true -utf8 -w 0 -qiubnm 2>/dev/null |
  157. grep -iav ".*generator.*HTML.*Tidy.*>$" 2>/dev/null |
  158. sponge "{}"
  159. >/dev/null
  160. 2>&1' \
  161. printf '%s\n' \
  162. "Done" ||
  163. true
  164. :
  165. printf '%s\n' \
  166. "$(date)" \
  167. >./.timestamp &&
  168. git add ./.timestamp
  169. :
  170. printf '%s\n' \
  171. "Preparing commit..." ||
  172. true
  173. :
  174. git gc --aggressive --prune=now ||
  175. true
  176. :
  177. SEMVER="$(eval printf '%s' "$(printf "%s" "$(semver-tool bump patch "$(printf '%d.%d.%d' "1" "$(grep '"_cXX": "' ./modules.json | \
  178. tr -d ',_"cX ' | cut -d ':' -f 2)" "$(cut -d '.' -f 3 ./.patch | \
  179. cut -d '.' -f 1)")") | sponge ./.patch")"; cat ./.patch)"
  180. git add -A && \
  181. git tag -s "${SEMVER:?}" -m "v${SEMVER:?} - $(date)" &&
  182. printf '%s\n' \
  183. "Set new semver tag: ${SEMVER}" &&\
  184. git commit -q -aS -m "Pushing Pages: $(date)" &&
  185. git pushall master &&
  186. printf '%s\n' "Complete."
  187. :