Created
January 30, 2020 04:17
-
-
Save sjx95/d25726209cf6cd2b00c7e55633cea4ca to your computer and use it in GitHub Desktop.
A simple converter for css in EPUB which covert 100vw/100vh to 100%
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 | |
# For batch convertion: | |
find *.epub | xargs -I FILE ./convert.sh FILE |
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 | |
usage() { | |
echo "Usage: ./convert.sh FILE.epub" | |
echo "Will save new EPUB under output/FILE.epub" | |
exit 1 | |
} | |
# Params check | |
if [ $# != 1 ]; then | |
usage | |
fi | |
FILE=$1 | |
if [ ! -f "$FILE" ]; then | |
usage | |
fi | |
# Clear ./tmp/ | |
if [ -d tmp ]; then | |
rm -r tmp | |
fi | |
mkdir tmp | |
cd tmp | |
# Unzip EPUB | |
unzip -q "../$FILE" | |
if [ -d OEBPS/Styles ]; then | |
cd OEBPS/Styles | |
else | |
exit 1 | |
fi | |
# For check | |
echo "========== Match: 100vw ==========" | |
grep "100vw" *.css | |
echo "========== Match: 100vh ==========" | |
grep "100vh" *.css | |
echo "==================================" | |
# Change 100vw/100vh -> 100% | |
sed "s/100vw/100\%/g" -i *.css | |
sed "s/100vh/100\%/g" -i *.css | |
cd ../.. | |
# Pack new EPUB files | |
if [ ! -d "../output" ]; then | |
mkdir ../output | |
fi | |
zip -qr "../output/$FILE" * | |
# Clean tmp/ | |
cd .. | |
rm -r tmp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment