forked from circleci/circleci-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_unused_images.sh
executable file
·55 lines (44 loc) · 1.79 KB
/
find_unused_images.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
#!/bin/bash
# Set the path to your Jekyll site's content directories
CONTENT_DIR1="./jekyll/_cci2"
CONTENT_DIR2="./jekyll/_includes"
CONTENT_DIR3="./jekyll/_cci2_ja"
# Set the path to your Jekyll site's assets directory
ASSETS_DIR="./jekyll/assets/img/docs"
# Create an array to store all image file paths
declare -a image_files
# Find all .png and .jpg files in the assets directory and store their paths in the array
while IFS= read -r -d '' file; do
image_files+=("$file")
done < <(find "$ASSETS_DIR" -type f \( -name '*.png' -o -name '*.jpg' \) -print0)
# Create an array to store all file paths in the content directories
declare -a content_files
# Find all files in the first content directory and store their paths in the array
while IFS= read -r -d '' file; do
content_files+=("$file")
done < <(find "$CONTENT_DIR1" -type f -print0)
# Find all files in the second content directory and store their paths in the array
while IFS= read -r -d '' file; do
content_files+=("$file")
done < <(find "$CONTENT_DIR2" -type f -print0)
# Find all files in the third content directory and store their paths in the array
while IFS= read -r -d '' file; do
content_files+=("$file")
done < <(find "$CONTENT_DIR3" -type f -print0)
# Loop through each image file
for image_file in "${image_files[@]}"; do
# Set a flag to indicate if the image file is referenced
referenced=false
# Loop through each content file
for content_file in "${content_files[@]}"; do
# Check if the image file is referenced in the content file
if grep -q "$(basename "$image_file")" "$content_file"; then
referenced=true
break
fi
done
# If the image file is not referenced, print its path
if ! $referenced; then
echo "Unused image file: $image_file"
fi
done