|
4 | 4 | font="/System/Library/Fonts/Apple Symbols.ttf" |
5 | 5 | glyph="★" |
6 | 6 |
|
7 | | -set -e |
| 7 | +set -euo pipefail |
8 | 8 |
|
9 | | -if [[ ${#} -ne 1 ]]; then |
10 | | - echo "Generates icons in assets/icons/ and HTML include of icons in _includes/icons/" |
11 | | - echo "Usage: ${0##*/} <image-format>" |
| 9 | +if [[ ${#} -ne 3 ]]; then |
| 10 | + echo "Generates icons and HTML include of icons" |
| 11 | + echo "Usage: ${0##*/} <scss_path> <output_path_prefix> <image-format>" |
12 | 12 | echo "<image-format> can be one of: jpg png webp svg" |
13 | 13 | exit 1 |
14 | 14 | fi |
15 | 15 |
|
16 | | -image_format=${1,,} |
| 16 | +dirname="${0%/*}" |
| 17 | +scss_path="${1}" |
| 18 | +output_path_prefix="${2}" |
| 19 | +icon_output_dir="${output_path_prefix}/assets/icons" |
| 20 | +include_input_dir="${icon_output_dir}" |
| 21 | +include_output_dir="${output_path_prefix}/_includes/icons" |
| 22 | +image_format="${3,,}" |
17 | 23 | named_colors="aliceblue antiquewhite aqua aquamarine azure beige bisque black blanchedalmond blue blueviolet brown burlywood cadetblue chartreuse chocolate coral cornflowerblue cornsilk crimson cyan darkblue darkcyan darkgoldenrod darkgray darkgreen darkgrey darkkhaki darkmagenta darkolivegreen darkorange darkorchid darkred darksalmon darkseagreen darkslateblue darkslategray darkslategrey darkturquoise darkviolet deeppink deepskyblue dimgray dimgrey dodgerblue firebrick floralwhite forestgreen fuchsia gainsboro ghostwhite gold goldenrod gray green greenyellow grey honeydew hotpink indianred indigo ivory khaki lavender lavenderblush lawngreen lemonchiffon lightblue lightcoral lightcyan lightgoldenrodyellow lightgray lightgreen lightgrey lightpink lightsalmon lightseagreen lightskyblue lightslategray lightslategrey lightsteelblue lightyellow lime limegreen linen magenta maroon mediumaquamarine mediumblue mediumorchid mediumpurple mediumseagreen mediumslateblue mediumspringgreen mediumturquoise mediumvioletred midnightblue mintcream mistyrose moccasin navajowhite navy oldlace olive olivedrab orange orangered orchid palegoldenrod palegreen paleturquoise palevioletred papayawhip peachpuff peru pink plum powderblue purple rebeccapurple red rosybrown royalblue saddlebrown salmon sandybrown seagreen seashell sienna silver skyblue slateblue slategray slategrey snow springgreen steelblue tan teal thistle tomato turquoise violet wheat white whitesmoke yellow yellowgreen" |
18 | 24 |
|
19 | 25 | shopt -s nullglob |
20 | | -for scss in ../assets/css/*.scss; do |
21 | | - basename=$(basename "${scss}") |
22 | | - theme_color=${basename%.*} |
| 26 | +for scss in "${scss_path}"/*.scss; do |
| 27 | + basename="${scss##*/}" |
| 28 | + theme_color="${basename%.*}" |
23 | 29 |
|
24 | | - if [[ ${theme_color} == "none" ]]; then |
| 30 | + if [[ "${theme_color}" == "none" ]]; then |
| 31 | + "${dirname}/generate-icon-include.sh" "${include_input_dir}" "${include_output_dir}" "${theme_color}" "${image_format}" |
25 | 32 | continue |
26 | 33 | fi |
27 | 34 |
|
28 | 35 | if [[ ${named_colors} =~ (^|[[:space:]])${theme_color}($|[[:space:]]) ]]; then |
29 | | - if [[ ${theme_color} == "white" ]]; then |
30 | | - if [[ ${image_format} == "svg" ]]; then |
31 | | - ./generate-icon-svg.sh white black ${theme_color}.svg |
| 36 | + if [[ "${theme_color}" == "white" ]]; then |
| 37 | + if [[ "${image_format}" == "svg" ]]; then |
| 38 | + "${dirname}/generate-icon-svg.sh" "${icon_output_dir}" white black "${theme_color}.svg" |
32 | 39 | else |
33 | | - ./generate-icon-unicode.sh white black "${font}" ${glyph} ${image_format} |
| 40 | + "${dirname}/generate-icon-unicode.sh" "${icon_output_dir}" white black "${font}" "${glyph}" "${image_format}" |
34 | 41 | fi |
35 | | - elif [[ ${theme_color} == "grey" && ${image_format} != "svg" ]]; then |
| 42 | + elif [[ "${theme_color}" == "grey" && "${image_format}" != "svg" ]]; then |
36 | 43 | # Grey is much lighter in convert |
37 | | - ./generate-icon-unicode.sh \#808080 white "${font}" ${glyph} ${image_format} grey |
| 44 | + "${dirname}/generate-icon-unicode.sh" "${icon_output_dir}" "#808080" white "${font}" "${glyph}" "${image_format}" grey |
38 | 45 | else |
39 | | - if [[ ${image_format} == "svg" ]]; then |
40 | | - ./generate-icon-svg.sh ${theme_color} white ${theme_color}.svg |
| 46 | + if [[ "${image_format}" == "svg" ]]; then |
| 47 | + "${dirname}/generate-icon-svg.sh" "${icon_output_dir}" "${theme_color}" white "${theme_color}.svg" |
41 | 48 | else |
42 | | - ./generate-icon-unicode.sh ${theme_color} white "${font}" ${glyph} ${image_format} |
| 49 | + "${dirname}/generate-icon-unicode.sh" "${icon_output_dir}" "${theme_color}" white "${font}" "${glyph}" "${image_format}" |
43 | 50 | fi |
44 | 51 | fi |
45 | 52 | else |
46 | | - # Hash symbol cannot be part of the scss filename, otherwise it cannot be HTTP-served |
47 | | - if [[ ${image_format} == "svg" ]]; then |
48 | | - ./generate-icon-svg.sh \#${theme_color} white ${theme_color}.svg |
| 53 | + # Hash symbol cannot be part of the SCSS filename, otherwise it cannot be HTTP-served |
| 54 | + if [[ "${image_format}" == "svg" ]]; then |
| 55 | + "${dirname}/generate-icon-svg.sh" "${icon_output_dir}" "#${theme_color}" white "${theme_color}.svg" |
49 | 56 | else |
50 | | - ./generate-icon-unicode.sh \#${theme_color} white "${font}" ${glyph} ${image_format} ${theme_color} |
| 57 | + "${dirname}/generate-icon-unicode.sh" "${icon_output_dir}" "#${theme_color}" white "${font}" "${glyph}" "${image_format}" "${theme_color}" |
51 | 58 | fi |
52 | 59 | fi |
53 | 60 |
|
54 | | - ./generate-icon-include.sh ${theme_color} ${image_format} |
| 61 | + "${dirname}/generate-icon-include.sh" "${include_input_dir}" "${include_output_dir}" "${theme_color}" "${image_format}" |
55 | 62 | done |
56 | 63 | shopt -u nullglob |
0 commit comments