diff --git a/server/gendocs.sh b/server/gendocs.sh new file mode 100755 index 0000000..01b0643 --- /dev/null +++ b/server/gendocs.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +set -euo pipefail + +# Function to generate anchor from package path +generate_anchor() { + echo "$1" | tr '/' '-' +} + +# Create documentation file +echo "# NovaMD Package Documentation + +Generated documentation for all packages in the NovaMD project. + +## Table of Contents +" > documentation.md + +# Find all directories containing .go files (excluding test files) +# Sort them for consistent output +PACKAGES=$(find . -type f -name "*.go" ! -name "*_test.go" -exec dirname {} \; | sort -u | grep -v "/\.") + +# Generate table of contents +for PKG in $PACKAGES; do + # Strip leading ./ + PKG_PATH=${PKG#./} + # Skip if empty + [ -z "$PKG_PATH" ] && continue + + ANCHOR=$(generate_anchor "$PKG_PATH") + echo "- [$PKG_PATH](#$ANCHOR)" >> documentation.md +done + +echo "" >> documentation.md + +# Generate documentation for each package +for PKG in $PACKAGES; do + # Strip leading ./ + PKG_PATH=${PKG#./} + # Skip if empty + [ -z "$PKG_PATH" ] && continue + + echo "## $PKG_PATH" >> documentation.md + echo "" >> documentation.md + echo '```go' >> documentation.md + go doc -all "./$PKG_PATH" >> documentation.md + echo '```' >> documentation.md + echo "" >> documentation.md +done + +echo "Documentation generated in documentation.md" \ No newline at end of file