gen-doc.sh 916 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #!/bin/sh
  2. #
  3. # Generate documentation
  4. #
  5. basedir="$(dirname "$0")"
  6. [ "$(echo "$basedir" | cut -c1)" = '/' ] || basedir="$PWD/$basedir"
  7. srcdir="$basedir/.."
  8. die()
  9. {
  10. echo "$*" >&2
  11. exit 1
  12. }
  13. gen()
  14. {
  15. local md="$1"
  16. local docname="$(basename "$md" .md)"
  17. local dir="$(dirname "$md")"
  18. local html="$dir/$docname.html"
  19. echo "Generating $(realpath --relative-to="$srcdir" "$html") from $(realpath --relative-to="$srcdir" "$md") ..."
  20. echo "<!DOCTYPE html><html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"></head><body>" > "$html" ||\
  21. die "Failed to generate"
  22. python3 -c "from readme_renderer.markdown import render; print(render(open('$md', 'r').read()))" >> "$html" ||\
  23. die "Failed to generate"
  24. echo "</body></html>" >> "$html" ||\
  25. die "Failed to generate"
  26. }
  27. for i in $(find "$srcdir" \( -name submodules -prune \) -o \( -name '*.md' -print \)); do
  28. gen "$i"
  29. done
  30. exit 0