test: add coarse test for unused media files

Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
This commit is contained in:
David Karlsson 2024-05-20 18:55:19 +02:00
parent 8be3964c58
commit aee1cfc81d
1 changed files with 23 additions and 0 deletions

23
scripts/test_unused_media.sh Executable file
View File

@ -0,0 +1,23 @@
#!/usr/bin/env sh
# Find all media files {svg,png,webp,mp4,jpg,jpeg} in {content,static}
MEDIA=$(fd . -e "svg" -e "png" -e "webp" -e "mp4" -e "jpg" -e "jpeg" ./content ./static)
TEMPFILE=$(mktemp)
for file in $MEDIA; do
rg -q "$(basename $file)"
if [ $? -ne 0 ]; then
echo "$file" >> "$TEMPFILE"
fi
done
UNUSED_FILES=$(< $TEMPFILE)
rm $TEMPFILE
if [ -z "$UNUSED_FILES" ]; then
exit 0
else
echo "$(echo "$UNUSED_FILES" | wc -l) unused media files. Please remove them."
printf "%s\n" ${UNUSED_FILES[@]}
exit 1
fi