-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmkindex.sh
executable file
·95 lines (77 loc) · 2.55 KB
/
mkindex.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
# Set the base URL
BASE_URL="https://images.jointheleague.org"
# Set the directory to scan
DIRECTORY="."
# Create the top-level README.md file
TOP_LEVEL_README="README.md"
# Function to list image files in a directory and create a README.md file
list_images() {
local DIR=$1
local REL_DIR=$2
# Create the directory-specific README.md file
local README_FILE="$DIR/README.md"
echo "# Images in ${REL_DIR:-Root Directory}" > $README_FILE
echo "" >> $README_FILE
echo "<!-- This README lists all image files in the ${REL_DIR:-root} directory -->" >> $README_FILE
echo "<table>" >> $README_FILE
echo " <tr>" >> $README_FILE
echo " <th>Link</th>" >> $README_FILE
echo " <th>Image</th>" >> $README_FILE
echo " </tr>" >> $README_FILE
local FILE_COUNT=0
for FILE in "$DIR"/*;
do
if [ -f "$FILE" ]; then
case "$FILE" in
*.png|*.jpg|*.jpeg|*.gif|*.bmp|*.tiff)
local REL_PATH="$REL_DIR/$(basename "$FILE")"
local URL="$BASE_URL$REL_PATH"
echo " <tr>" >> $README_FILE
echo " <td><a href=\"$URL\">${REL_PATH##*/}</a></td>" >> $README_FILE
echo " <td><img src=\"$URL\" alt=\"${REL_PATH##*/}\" style=\"max-width:200px; max-height:200px;\"></td>" >> $README_FILE
echo " </tr>" >> $README_FILE
FILE_COUNT=$((FILE_COUNT+1))
;;
esac
fi
done
if [ $FILE_COUNT -gt 0 ]; then
echo "</table>" >> $README_FILE
echo "" >> $README_FILE
else
# Remove the README.md file if no image files were found
rm $README_FILE
fi
# Add to top-level README table of contents if a README.md was created
if [ -f "$README_FILE" ]; then
local TOC_LINK="[${REL_DIR:-Root Directory}](${REL_DIR:-.}/README.md)"
echo "- $TOC_LINK" >> toc.tmp
fi
}
# Function to recursively process directories
process_directories() {
local DIR=$1
local REL_DIR=$2
list_images "$DIR" "$REL_DIR"
for SUB_DIR in "$DIR"/*;
do
if [ -d "$SUB_DIR" ]; then
process_directories "$SUB_DIR" "$REL_DIR/$(basename "$SUB_DIR")"
fi
done
}
# Ensure the toc.tmp file is empty
> toc.tmp
# Start processing directories from the initial directory
awk '/<!-- start generated content -->/ {exit} {print}' README.md > readme_top.md
echo "<!-- start generated content -->" >> readme_top.md
echo "" >> readme_top.md
process_directories "$DIRECTORY" ""
#echo "" >> $TOP_LEVEL_README
cat readme_top.md toc.tmp >> $TOP_LEVEL_README
rm toc.tmp
rm readme_top.md
echo "README.md files have been created successfully."
git commit -a -m'Update'
git push