-
Notifications
You must be signed in to change notification settings - Fork 3
/
raw-publish.sh
executable file
·158 lines (125 loc) · 3.35 KB
/
raw-publish.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#
# Load config file
#
if [ -f $FILE ]; then
. config.sh
fi
cd $WORKING_DIR
#
# Define a function for logging
#
function say {
if [[ $JAWS_COLOR -eq 1 ]]; then
echo ""
echo -e "\033[4;32m$1\033[0m"
else
echo ""
echo $1
echo "----------------------------------"
fi
}
#
# immediately regenerate the site
#
say "Generating Site"
$JAWS_GENERATE
#
# Use absolute CDN paths for images, css, js
#
say "Replacing CDN Paths"
VERBOSE=
if [[ $JAWS_VERBOSE -eq 1 ]]; then
VERBOSE="-exec echo {} ;"
fi
# Escape path for sed
STATICCDN=${JAWS_STATICCDN//\//\\\/}
IMAGECDN=${JAWS_STATICCDN//\//\\\/}
find -E _site \
-type f \
-regex '.*\.(html|js|css)' \
$VERBOSE \
-exec sed -Ei '' "s/\"\/([^\/][^\"]+\.(css|js))\"/\"$STATICCDN\1?r=$JAWS_REVISION\"/g" {} \; \
-exec sed -Ei '' "s/\"\/([^\/][^\"]+\.(png|jpg|jpeg|gif))\"/\"$IMAGECDN\1?r=$JAWS_REVISION\"/g" {} \; \
-exec sed -Ei '' "s/'\/([^\/][^']+\.(css|js))'/'$STATICCDN\1?r=$JAWS_REVISION'/g" {} \; \
-exec sed -Ei '' "s/'\/([^\/][^']+\.(png|jpg|jpeg|gif))'/'$IMAGECDN\1?r=$JAWS_REVISION'/g" {} \;
# TODO - this should really be replaced by a proper parser to be safe
# Dissection of horrible regex:
# "/([^/] - Quoted, absolute paths. Make sure to exclude no-protocol links e.g., //ajax.googleapis.com/
# [^"]*+ - Any non-quote character. It's ok that this is greedy unless you do something like not closing your quotes
# \.(css|js) - Different file extensions for which to replace
# )" - End
#
# Minify JS, CSS, and HTML files
#
say "Minifying JS"
find _site -name '*.js' \
$VERBOSE \
-exec java -jar $SCRIPTS_DIR/yuicompressor.jar -o {} {} \;
say "Minifying CSS"
find _site -name '*.css' \
$VERBOSE \
-exec java -jar $SCRIPTS_DIR/yuicompressor.jar -o {} {} \;
say "Minifying HTML"
find _site -name '*.html' \
$VERBOSE \
-exec java -jar $SCRIPTS_DIR/htmlcompressor.jar \
--compress-js \
--compress-css \
--remove-intertag-spaces \
--type html \
-o {} {} \;
#
# gzip text-based files
#
say "Compressing text files"
# TODO additional prefixes like .txt? document files? configurable, ideally
find _site -name '*.html' $VERBOSE -exec $JAWS_ZIPCMD {} \; -exec mv {}.gz {} \;
find _site -name '*.xml' $VERBOSE -exec $JAWS_ZIPCMD {} \; -exec mv {}.gz {} \;
find _site -name '*.js' $VERBOSE -exec $JAWS_ZIPCMD {} \; -exec mv {}.gz {} \;
find _site -name '*.css' $VERBOSE -exec $JAWS_ZIPCMD {} \; -exec mv {}.gz {} \;
#
# sync gzipped html/xml:
#
say "Syncing HTML/XML"
s3cmd sync \
--progress \
--guess-mime-type \
--acl-public \
$DELETE \
$INVALIDATE \
--add-header 'Content-Encoding:gzip' \
--exclude '*.*' \
--include '*.html' \
--include '*.xml' \
_site/ $JAWS_BUCKET
#
# sync gzipped files which get a timestamp, so we can cache for a very long time
#
say "Syncing CSS/JS"
s3cmd sync \
--progress \
--guess-mime-type \
--acl-public \
$INVALIDATE \
--add-header 'Content-Encoding:gzip' \
--add-header "Cache-Control: max-age=$JAWS_LONGCACHE" \
--exclude '*.*' \
--include '*.js' \
--include '*.css' \
_site/ $JAWS_BUCKET
#
# sync remaining files, e.g., images, documents
#
say "Syncing Remaining Files"
s3cmd sync \
--progress \
--guess-mime-type \
--acl-public \
$INVALIDATE \
--add-header "Cache-Control: max-age=$JAWS_SHORTCACHE" \
--exclude '*.html' \
--exclude '*.xml' \
--exclude '*.js' \
--exclude '*.css' \
_site/ $JAWS_BUCKET
say "Done."