-
Notifications
You must be signed in to change notification settings - Fork 167
/
check_retina.sh
executable file
·74 lines (65 loc) · 2.35 KB
/
check_retina.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
#!/bin/bash
#
# check_retina.sh
#
# This script tries to ensure that all scalar images (i.e. a ".jpg" or a
# ".png") have a companion retina file, that is one that has a "@2x" before the
# extension and is 4x the resolution of its original. The script runs in CI to
# try and keep me from getting lazy and not finding retina assets.
#
# This is so that images look better on retina displays like newer Mac laptops,
# iPhones, and iPads. While the sources of images still point to the non-retina
# version, a JS script that's loaded (retina.js) replaces them with retina
# content in the DOM if appropriate for a user's device.
#
allowed_exceptions=(
# Images that don't have a retina version by design.
./content/images/favicon/favicon-*.jpg
./content/images/favicon/favicon-*.png
./content/images/favicon/nanoglyph-*.jpg
./content/images/favicon/nanoglyph-*.png
./content/images/favicon/passages-*.jpg
"./content/images/standin_00.jpg"
"./content/images/standin_01.jpg"
"./content/images/standin_02.jpg"
"./content/images/standin_03.jpg"
"./content/images/standin_04.jpg"
"./content/images/standin_portrait_00.jpg"
# Images that were never high resolution enough to merit a retina version.
"./content/images/nanoglyphs/012-virtual-worlds/lester-masked.png"
# Other.
"./content/images/sequences-project/sample-huge.png"
)
find_images() {
find ./content -type f \( \
\( \
-not \( \
-iname "*@2x.*" \
\) \
\) -and \( \
-iname "*.jpg" \
-o \
-iname "*.png" \
\) \
\)
}
bad_images=()
for image in $(find_images); do
extension="${image##*.}"
base=$(basename $image .$extension)
retina=${image/"$base.$extension"/"$base@2x.$extension"}
if [[ ! -f "$retina" ]]; then
bad_images+=("$image")
fi
done
# This insane bash-fu takes the difference between two arrays. If either we
# have an exception that no longer exists or have an image without retina
# that's not in the exceptions list, it will be returned.
#
# Note that bad_images changes from an array to a standard string.
bad_images=$(echo "${allowed_exceptions[@]} ${bad_images[@]}" | tr ' ' '\n' | sort | uniq -u)
if [[ -n "${bad_images}" ]]; then
echo "!!! no retina assets for the following images: "
echo "${bad_images}"
exit 1
fi