暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

generate_docs.sh 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/bin/bash
  2. # SPDX-FileCopyrightText: 2024 Thomas Buck <thomas@xythobuz.de>
  3. # SPDX-License-Identifier: CERN-OHL-S-2.0+
  4. #
  5. # ------------------------------------------------------------------------------
  6. # | Copyright (c) 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://git.xythobuz.de/thomas/drumkit |
  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="../pcb/drumkit.kicad_sch ../pcb2/lars2.kicad_sch"
  28. INPCB="../pcb/drumkit.kicad_pcb ../pcb2/lars2.kicad_pcb"
  29. cd "$(dirname "$0")"
  30. #echo "Generating plots"
  31. rm -rf src/plot
  32. #../pcb/generate_plot.sh
  33. cp -r ../pcb/plot src
  34. #echo
  35. #echo "Generating plots 2"
  36. #../pcb/generate_plot.sh
  37. cp -r ../pcb2/plot/* src/plot/
  38. #echo
  39. #echo "Generating stls"
  40. rm -rf src/stl
  41. #../3dprint/generate_stls.sh
  42. cp -r ../3dprint/stl src
  43. #echo
  44. INSTL=`ls ../3dprint/stl/*.stl`
  45. for path in $INSCH
  46. do
  47. IN=`echo $path | sed "s:../pcb.\\?/::g"`
  48. o="src/inc_$IN.md"
  49. echo "Include for $IN at $o"
  50. rm -rf $o
  51. echo "<script src=\"js/svg-pan-zoom.js\" charset=\"UTF-8\"></script>" >> $o
  52. for f in `ls src/plot/$IN.svg/*.svg | sort -r`; do
  53. file=`echo $f | sed 's:src/:./:g'`
  54. name=`echo $f | sed "s:src/plot/$IN.svg/::g" | sed 's:.svg::g'`
  55. echo "Sheet at $name"
  56. echo "<h2>$name</h2>" >> $o
  57. echo "<div style=\"background-color: white; border: 1px solid black;\">" >> $o
  58. echo "<embed type=\"image/svg+xml\" src=\"$file\" id=\"pz_$name\" style=\"width:100%;\"/>" >> $o
  59. echo "<script>" >> $o
  60. echo "document.getElementById('pz_$name').addEventListener('load', function(){" >> $o
  61. echo "svgPanZoom(document.getElementById('pz_$name'), {controlIconsEnabled: true, minZoom: 1.0});" >> $o
  62. echo "})" >> $o
  63. echo "</script>" >> $o
  64. echo "</div>" >> $o
  65. echo >> $o
  66. echo "[Direct link to \`$name\`]($file)." >> $o
  67. echo >> $o
  68. done
  69. echo
  70. done
  71. plot_3d() {
  72. echo '<script type="importmap">' >> $1
  73. echo ' {' >> $1
  74. echo ' "imports": {' >> $1
  75. echo ' "three": "https://cdn.jsdelivr.net/npm/three@0.163.0/build/three.module.js",' >> $1
  76. echo ' "three/addons/": "https://cdn.jsdelivr.net/npm/three@0.163.0/examples/jsm/"' >> $1
  77. echo ' }' >> $1
  78. echo ' }' >> $1
  79. echo '</script>' >> $1
  80. echo "<p>Status: \"<span id=\"3d_info_$2\">Preparing 3D model...</span>\"</p>" >> $1
  81. echo "<div id=\"3d_viewer_$2\" style=\"width: 100%; height: 100%; background-color: white; border: 1px solid black; position: relative;\"></div>" >> $1
  82. echo '<script type="module">' >> $1
  83. echo " var info = document.getElementById(\"3d_info_$2\");" >> $1
  84. echo " var view = document.getElementById(\"3d_viewer_$2\");" >> $1
  85. echo ' view.style.height = Math.floor(view.clientWidth * 0.707) + "px";' >> $1
  86. echo ' import { init_3d } from "./js/3d.js";' >> $1
  87. echo " init_3d(\"$3\", view, info, view.clientWidth, view.clientHeight);" >> $1
  88. echo '</script>' >> $1
  89. }
  90. for path in $INPCB
  91. do
  92. IN=`echo $path | sed "s:../pcb.\\?/::g"`
  93. o="src/inc_$IN.md"
  94. file="plot/$IN.wrl"
  95. name=`echo $file | sed "s:plot/::g" | sed 's:.wrl::g'`
  96. echo "Include for $IN at $o, $file, $name"
  97. rm -rf $o
  98. plot_3d $o $name $file
  99. done
  100. echo
  101. for IN in $INSTL
  102. do
  103. o=`echo $IN | sed "s:../3dprint/stl/:src/inc_:g" | sed "s:.stl:.stl.md:g"`
  104. file=`echo $IN | sed "s:../3dprint/::g"`
  105. name=`echo $file | sed "s:stl/::g" | sed 's:.stl::g'`
  106. echo "Include for $IN at $o, $file, $name"
  107. rm -rf $o
  108. plot_3d $o $name $file
  109. done
  110. echo
  111. echo "Generating docs"
  112. if [ "$1" = "serve" ] ; then
  113. mdbook serve --open
  114. elif [ "$1" = "build" ] ; then
  115. mdbook build
  116. else
  117. echo "Invalid command. 'build' or 'serve'."
  118. fi