No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

generate_docs.sh 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #!/bin/bash
  2. # SPDX-FileCopyrightText: 2023 - 2024 Thomas Buck <thomas@xythobuz.de>
  3. # SPDX-License-Identifier: CERN-OHL-S-2.0+
  4. #
  5. # ------------------------------------------------------------------------------
  6. # | Copyright (c) 2023 - 2024 Thomas Buck <thomas@xythobuz.de> |
  7. # | |
  8. # | This source describes Open Hardware and is licensed under the CERN-OHL-S v2 |
  9. # | or any later version. |
  10. # | |
  11. # | You may redistribute and modify this source and make products using it under |
  12. # | the terms of the CERN-OHL-S v2 (https://ohwr.org/cern_ohl_s_v2.txt) |
  13. # | or any later version. |
  14. # | |
  15. # | This source is distributed WITHOUT ANY EXPRESS OR IMPLIED WARRANTY, |
  16. # | INCLUDING OF MERCHANTABILITY, SATISFACTORY QUALITY AND FITNESS FOR A |
  17. # | PARTICULAR PURPOSE. Please see the CERN-OHL-S v2 (or any later version) |
  18. # | for applicable conditions. |
  19. # | |
  20. # | Source location: https://github.com/drinkrobotics/dispensy |
  21. # | |
  22. # | As per CERN-OHL-S v2 section 4, should You produce hardware based on this |
  23. # | source, You must where practicable maintain the Source Location visible |
  24. # | on the external case of the Gizmo or other products you make using this |
  25. # | source. |
  26. # ------------------------------------------------------------------------------
  27. INSCH="../hardware/dispensy.kicad_sch"
  28. INPCB="../hardware/dispensy.kicad_pcb"
  29. cd "$(dirname "$0")"
  30. if [ "$1" = "build" ] ; then
  31. echo "Generating plots"
  32. ../hardware/generate_plot.sh
  33. echo
  34. echo "Generating fab"
  35. ../hardware/generate_fab.sh
  36. echo
  37. fi
  38. rm -rf src/plot
  39. cp -r ../hardware/plot src
  40. for path in $INSCH
  41. do
  42. IN=`echo $path | sed "s:../hardware/::g"`
  43. o="src/inc_$IN.md"
  44. echo "Include for $IN at $o"
  45. rm -rf $o
  46. echo "<script src=\"js/svg-pan-zoom.js\" charset=\"UTF-8\"></script>" >> $o
  47. for f in `ls src/plot/$IN.svg/*.svg | sort -r`; do
  48. file=`echo $f | sed 's:src/:./:g'`
  49. name=`echo $f | sed "s:src/plot/$IN.svg/::g" | sed 's:.svg::g'`
  50. echo "Sheet at $name"
  51. echo "<h2>$name</h2>" >> $o
  52. echo "<div style=\"background-color: white; border: 1px solid black;\">" >> $o
  53. echo "<embed type=\"image/svg+xml\" src=\"$file\" id=\"pz_$name\" style=\"width:100%;\"/>" >> $o
  54. echo "<script>" >> $o
  55. echo "document.getElementById('pz_$name').addEventListener('load', function(){" >> $o
  56. echo "svgPanZoom(document.getElementById('pz_$name'), {controlIconsEnabled: true, minZoom: 1.0});" >> $o
  57. echo "})" >> $o
  58. echo "</script>" >> $o
  59. echo "</div>" >> $o
  60. echo >> $o
  61. echo "[Direct link to \`$name\`]($file)." >> $o
  62. echo >> $o
  63. done
  64. echo
  65. done
  66. plot_3d() {
  67. echo '<script type="importmap">' >> $1
  68. echo ' {' >> $1
  69. echo ' "imports": {' >> $1
  70. echo ' "three": "https://cdn.jsdelivr.net/npm/three@0.163.0/build/three.module.js",' >> $1
  71. echo ' "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.163.0/examples/jsm/"' >> $1
  72. echo ' }' >> $1
  73. echo ' }' >> $1
  74. echo '</script>' >> $1
  75. echo "<p>Status: \"<span id=\"3d_info_$2\">Preparing 3D model...</span>\"</p>" >> $1
  76. echo "<div id=\"3d_viewer_$2\" style=\"width: 100%; height: 100%; background-color: white; border: 1px solid black; position: relative;\"></div>" >> $1
  77. echo '<script type="module">' >> $1
  78. echo " var info = document.getElementById(\"3d_info_$2\");" >> $1
  79. echo " var view = document.getElementById(\"3d_viewer_$2\");" >> $1
  80. echo ' view.style.height = Math.floor(view.clientWidth * 0.707) + "px";' >> $1
  81. echo ' import { init_3d } from "./js/3d.js";' >> $1
  82. echo " init_3d(\"$3\", view, info, view.clientWidth, view.clientHeight);" >> $1
  83. echo '</script>' >> $1
  84. }
  85. for path in $INPCB
  86. do
  87. IN=`echo $path | sed "s:../hardware/::g"`
  88. o="src/inc_$IN.md"
  89. file="plot/$IN.wrl"
  90. name=`echo $file | sed "s:plot/::g" | sed 's:.wrl::g'`
  91. echo "Include for $IN at $o, $file, $name"
  92. rm -rf $o
  93. plot_3d $o $name $file
  94. done
  95. echo
  96. echo "Generating docs"
  97. if [ "$1" = "serve" ] ; then
  98. mdbook serve --open
  99. elif [ "$1" = "build" ] ; then
  100. mdbook build
  101. else
  102. echo "Invalid command. 'build' or 'serve'."
  103. fi