gen-doc.sh 949 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 rst="$1"
  16. local docname="$(basename "$rst" .rst)"
  17. local dir="$(dirname "$rst")"
  18. local html="$dir/$docname.html"
  19. local md="$dir/$docname.md"
  20. echo "Generating $(realpath --relative-to="$srcdir" "$html") from $(realpath --relative-to="$srcdir" "$rst") ..."
  21. python3 -m readme_renderer -o "$html" "$rst" ||\
  22. die "Failed to generate HTML."
  23. echo "Generating $(realpath --relative-to="$srcdir" "$md") from $(realpath --relative-to="$srcdir" "$rst") ..."
  24. pandoc -s -o "$md" "$rst" ||\
  25. die "Failed to generate MD."
  26. }
  27. for i in $(find "$srcdir" \( -name release-archives -prune \) -o \( -name target -prune \) -o \( -name '*.rst' -print \)); do
  28. gen "$i"
  29. done
  30. cd "$srcdir" || die "cd failed."
  31. cargo doc || die "cargo doc failed."
  32. exit 0