-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
minify
executable file
·95 lines (90 loc) · 2.82 KB
/
minify
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
#!/bin/bash
#
# Minify all the source HTML, JavaScript and CSS and save to /dist/ folder.
#
# Copyright: Copyright 2018-2020 Justin Hartman (https://hartman.me)
# Author : Justin Hartman <justin@hartman.me> (https://hartman.me)
# License : https://opensource.org/licenses/AGPL-3.0 AGPL-3.0
# Version : 2.1.0
# Link : https://github.com/justinhartman/Apache-Error-Pages
# Since : 1.0.0
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
#######################################
# Clears out the distribution folder
# and re-creates the CSS folder.
# Globals:
# None
# Arguments:
# None
# Returns:
# String
#######################################
reset_dist() {
rm -rf ../dist/apache/*
mkdir ../dist/apache/css
echo "The ../dist/apache folder has been reset."
}
#######################################
# Run html-minifier to compress HTML
# and JavaScript.
# Globals:
# None
# Arguments:
# None
# Returns:
# String
#######################################
minfy_html() {
for VARIABLE in 400 401 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 421 422 423 424 426 428 429 431 451 500 501 502 503 504 505 506 507 508 510 511; do
HTML_FILE_NAME="$VARIABLE.html"
html-minifier --collapse-whitespace --remove-comments --remove-optional-tags --remove-redundant-attributes --remove-script-type-attributes --remove-tag-whitespace --use-short-doctype --minify-css true --minify-js true ../src/apache/$HTML_FILE_NAME -o ../dist/apache/$HTML_FILE_NAME
echo "$HTML_FILE_NAME minified"
done
}
#######################################
# Run postcss to compress all the
# CSS files.
# Globals:
# None
# Arguments:
# None
# Returns:
# String
#######################################
minify_css() {
../node_modules/.bin/postcss ../src/css/ -m --dir ../dist/apache/css/
echo "All the CSS files have now been minified."
}
#######################################
# Copy all the static items that
# aren't compressed.
# Globals:
# None
# Arguments:
# None
# Returns:
# String
#######################################
copy_assets() {
echo "Copying the assets and fonts..."
cp -R ../src/static/* ../dist/apache/
}
reset_dist
minfy_html
minify_css
copy_assets
echo "Minification Complete!"
exit 0