Initial commit
This commit is contained in:
Executable
+36
@@ -0,0 +1,36 @@
|
||||
#!/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)."
|
||||
|
||||
Reference in New Issue
Block a user