#!/bin/sh # # Generate documentation # basedir="$(dirname "$0")" [ "$(echo "$basedir" | cut -c1)" = '/' ] || basedir="$PWD/$basedir" srcdir="$basedir/.." die() { echo "$*" >&2 exit 1 } gen() { local md="$1" local docname="$(basename "$md" .md)" local dir="$(dirname "$md")" local html="$dir/$docname.html" echo "Generating $(realpath --relative-to="$srcdir" "$html") from $(realpath --relative-to="$srcdir" "$md") ..." echo "
" > "$html" ||\ die "Failed to generate" python3 -c "from readme_renderer.markdown import render; print(render(open('$md', 'r').read()))" >> "$html" ||\ die "Failed to generate" echo "" >> "$html" ||\ die "Failed to generate" } for i in $(find "$srcdir" \( -name submodules -prune \) -o \( -name '*.md' -print \)); do gen "$i" done exit 0