-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbuilder.sh
executable file
·122 lines (90 loc) · 2.66 KB
/
builder.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
#!/usr/bin/env bash
set -Eeuo pipefail
# shellcheck source=/dev/null
source "${stdenv:?}/setup"
cp -r "${src:?}" src
chmod -R u+w src
cd src
patchPhase
spritesheets="icon markitup toast"
declare -A jses=(
[common]="$jquery $cookie $loadmask $reveal $minform common.js toast.js loggedout.js"
[link]="$longtable link.js"
[member]=" $showdown jquery.markitup.js markitup.set.js loggedin.js comment.js"
[dashboard]="$drcal dashboard.js"
[review]="$hotkeys $easing review.js"
[member-page]="member-page.js"
[reader]="reader.js"
)
declare -A csses=(
[common]="common.styl comment.styl toast.styl loadmask.styl reveal.styl $out/img/icon.css $out/img/toast.css"
[member]="markitup.styl $out/img/markitup.css"
[link]="link.styl"
[article]="article.styl"
[dashboard]="dashboard.styl"
[member-page]="member-page.styl"
[front]="front.styl"
[review]="review.styl"
[reader]="reader.styl"
)
mkdir -p "$out/js" "$out/img" "$out/css" "$out/articles"
# JavaScript
pushd js
for k in "${!jses[@]}"; do
uglifyjs ${jses[$k]} --mangle -o "$out/js/$k.js"
done
popd
# Images
pushd img
cp -r ./*.png ./*.gif off-the-shelf reader "$out/img/"
# TODO: Create an img manifest so that CSS files can cache-bust images.
## Spritesheets
### MarkItUp! sprites are famfamfam Silk icons.
mkdir markitup && pushd markitup
unzip "${silkicons:?}"
for icon in text_heading_1 text_heading_2 text_heading_3 text_bold text_italic text_list_bullets text_list_numbers picture link user_comment script_code tick; do
mv "icons/$icon.png" .;
done
rm -rf icons readme.html readme.txt
popd
for spritesheet in $spritesheets; do
glue "$spritesheet" "$out/img" --url=/img/ --cachebuster --crop
done
pngs=$(find "$out/img" -iname "*.png")
chmod +w "$pngs" "$out/img/off-the-shelf" && optipng -clobber "$pngs"
popd
# CSS
pushd css
for k in "${!csses[@]}"; do
args=""
for f in ${csses[$k]}; do
if [ "${f: -5}" == ".styl" ]; then
args+=" <(stylus < $f)"
else
args+=" $f"
fi
done
eval "cat $args > $out/css/$k.css"
done
for spritesheet in $spritesheets; do
rm "$out/img/$spritesheet.css"
done
## Some CSS comes from a theme I cannot redistribute.
cp off-the-shelf.css "$out/css/"
popd
# Documents
pushd articles
for article in *.markdown; do
pandoc --section-divs --mathjax -t html5+smart --toc --standalone --template=template.html < "$article" > "$out/articles/${article%.markdown}.html"
done
popd
# Audio
## These are not under revision control.
if [ -d audio ]; then
cp -r audio "$out/"
fi
# Store a manifest of the static assets (js/css/img).
# We can use this manifest for cache busting.
pushd "$out"
find js css img -type f -print0 | xargs -0 sha1sum > manifest
popd