Created
October 11, 2015 06:50
-
-
Save intsilence/61614424380dcd26e731 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
isDir() | |
{ | |
local dirName=$1 | |
if [ -d $dirName ]; then | |
echo true | |
else | |
echo false | |
fi | |
} | |
isImage() | |
{ | |
local fileName=$1 | |
if [[ $fileName == *png || $fileName == *jpg ]]; then | |
echo true | |
else | |
echo false | |
fi | |
} | |
isExistWebp() | |
{ | |
local fileName=$1 | |
fileName="${fileName}.webp" | |
if [ -f $fileName ]; then | |
echo true | |
else | |
echo false | |
fi | |
} | |
recursionDir() | |
{ | |
local dir=$1 | |
echo "current dir: ${dir}" | |
if $(isDir "${dir}") | |
then : | |
else | |
echo "error,please pass a dirctory"; | |
exit 1 | |
fi | |
local filelist=`ls -tr "${dir}"` | |
for filename in $filelist | |
do | |
local fullpath="${dir}"/"${filename}"; | |
if $(isDir "${fullpath}");then | |
recursionDir "${fullpath}" | |
else | |
if $(isImage "${fullpath}") && ! $(isExistWebp "${fullpath}");then | |
echo "${fullpath}.webp not exist!" | |
cwebp "${fullpath}" -o "${fullpath}.webp" | |
fi | |
fi | |
done | |
} | |
#usage: | |
recursionDir "./static" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment