-
Notifications
You must be signed in to change notification settings - Fork 2
/
minimizer.sh
executable file
·41 lines (33 loc) · 1.02 KB
/
minimizer.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
#!/bin/bash
# make sure that an argument was supplied
if [ $# -eq 0 ]
then
echo "No Smartmark directory supplied."
exit 1
fi
# help command
if [ $1 = "-h" ]; then
echo ""
echo "Convert HTML file into minimized Data URI bookmarklet. Usage:"
echo ""
echo "minimizer.sh FILE Minimize FILE/FILE.html into FILE/FILE.min.html"
echo "minimizer.sh -h Get help"
echo ""
exit 0
fi
FILE=$1
# make sure that the argument is a valid directory
if [ ! -d $FILE ]; then
echo "Smartmark directory '$FILE' not found in current working directory."
exit 1
fi
# make sure that there is a file inside of the directory
if [ ! -f $FILE/$FILE.html ]; then
echo "Directory '$FILE' does not contain a HTML file called $FILE.html"
exit 1
fi
# minimize the file using htmlcompressor
java -jar htmlcompressor.jar --compress-css -o $FILE/$FILE.min.html $FILE/$FILE.html
# prepend "data:text/html," so that the page works in the URL bar
echo "data:text/html," | cat - $FILE/$FILE.min.html > tempfile && mv tempfile $FILE/$FILE.min.html
exit 0