{pkgs}: pkgs.writeShellScriptBin "docs-parser" '' #!/usr/bin/env bash set -euo pipefail # Default paths DOCS_DIR="$HOME/ddubsos/docs" # Handle arguments MODE="''${1:-files}" CATEGORY="''${2:-AI}" LANGUAGE="''${3:-en}" usage() { cat </dev/null | sed 's/^# //' || echo "") if [[ -n "$title" ]]; then echo "$title" else # Fallback to clean filename get_clean_filename "$filepath" fi else get_clean_filename "$filepath" fi } # Main processing case "$MODE" in "files") # Generate JSON list of available files for a category echo "[" # Handle special "root" category for files in docs/ root directory if [[ "$CATEGORY" == "root" ]]; then # Find markdown files directly in docs root directory if [[ -d "$DOCS_DIR" ]]; then first=true while IFS= read -r -d "" filepath; do file_lang=$(get_language "$filepath") # Filter by requested language if [[ "$file_lang" == "$LANGUAGE" ]]; then clean_name=$(get_clean_filename "$filepath") title=$(get_title_from_file "$filepath") if [[ "$first" == "true" ]]; then first=false else echo "," fi cat <&2 exit 1 fi else # All files metadata with content echo "[" first=true if [[ -d "$DOCS_DIR/$CATEGORY" ]]; then while IFS= read -r -d "" filepath; do file_lang=$(get_language "$filepath") # Filter by requested language if [[ "$file_lang" == "$LANGUAGE" ]]; then clean_name=$(get_clean_filename "$filepath") title=$(get_title_from_file "$filepath") content=$(cat "$filepath" | ${pkgs.jq}/bin/jq -R -s .) if [[ "$first" == "true" ]]; then first=false else echo "," fi cat <&2 usage >&2 exit 1 ;; esac ''