37 lines
772 B
Bash
Executable File
37 lines
772 B
Bash
Executable File
#!/usr/bin/env sh
|
|
|
|
PHOTOS_DIR="photos"
|
|
OUTPUT_FILE="photos.json"
|
|
|
|
# Check photos directory exists
|
|
if [ ! -d "$PHOTOS_DIR" ]; then
|
|
echo "Error: '$PHOTOS_DIR' directory not found."
|
|
exit 1
|
|
fi
|
|
|
|
# Start JSON array
|
|
printf "[\n" > "$OUTPUT_FILE"
|
|
|
|
# Collect JPG files (case-insensitive), sorted
|
|
# Works on macOS + Linux
|
|
FILES=$(ls -1 "$PHOTOS_DIR" 2>/dev/null | grep -i '\.jpg$' | sort)
|
|
|
|
COUNT=0
|
|
TOTAL=$(printf "%s\n" "$FILES" | grep -c .)
|
|
|
|
printf "%s\n" "$FILES" | while IFS= read -r FILE; do
|
|
COUNT=$((COUNT + 1))
|
|
|
|
if [ "$COUNT" -lt "$TOTAL" ]; then
|
|
printf " \"%s\",\n" "$FILE" >> "$OUTPUT_FILE"
|
|
else
|
|
printf " \"%s\"\n" "$FILE" >> "$OUTPUT_FILE"
|
|
fi
|
|
done
|
|
|
|
# End JSON array
|
|
printf "]\n" >> "$OUTPUT_FILE"
|
|
|
|
echo "Generated $OUTPUT_FILE with $TOTAL image(s)."
|
|
|