-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-icon-font.sh
executable file
·57 lines (48 loc) · 2.16 KB
/
generate-icon-font.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
#!/bin/bash
# Effectively the prefix used in all classes, don't change this unless you plan a refactor!
FONT_PREFIX=ki
# The name of the font files [woff, eot, ...]
FONT_NAME=kaleidos-icons
# The location of the overview page for the icons in Ember
OVERVIEW_PAGE_PATH=app/components/styleguide/script-icons/template.hbs
# The folder containing all the SVG icons you intend to convert to the font
PATH_TO_SVG_FILES=./icon-font-svg-files
# Generate the font using the npm package
npx icon-font-generator $PATH_TO_SVG_FILES"/*.svg" \
--out "./public/fonts" \
--csspath "./app/styles/_icon-font.css" \
--cssfontsurl "/fonts/" \
--name $FONT_NAME \
--htmlpath "./tmp/icons-temp.html" \
--prefix $FONT_PREFIX \
--height=1000
# The two following fixes are performed so that xmllint doesn't argue about broken tags...
# Fixing broken <br> tags to become <br />
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Linux
sed -i -e 's/<br>/<br \/>/g' "tmp/icons-temp.html"
elif [[ "$OSTYPE" == "darwin"* ]]; then
# Mac OSX
sed -i '' -e 's/\<br\>/\<br \/\>/g' "tmp/icons-temp.html"
fi
# Fix the broken meta tag that was generated
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Linux
sed -i -e 's/<meta charset="UTF-8">/<meta charset="UTF-8"\/>/g' "tmp/icons-temp.html" "tmp/icons-temp.html"
elif [[ "$OSTYPE" == "darwin"* ]]; then
# Mac OSX
sed -i '' -e 's/\<meta charset="UTF-8"\>/\<meta charset="UTF-8"\/\>/g' "tmp/icons-temp.html"
fi
# Make the new overview page - disable linting, add an icons-page class wrapper, and copy the generated contents into this template
echo '{{!-- template-lint-disable --}}' > $OVERVIEW_PAGE_PATH \
&& echo '<div class="icons-page">' >> $OVERVIEW_PAGE_PATH \
&& xmllint --xpath "//body/child::*" "tmp/icons-temp.html" >> $OVERVIEW_PAGE_PATH \
&& printf "\n</div>" >> $OVERVIEW_PAGE_PATH
# Modify the overview page so that the prefix is included, that allows us to just copy paste icons from the overview
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Linux
sed -i -e "s/\"label\">/\"label\">test-/g" $OVERVIEW_PAGE_PATH
elif [[ "$OSTYPE" == "darwin"* ]]; then
# Mac OSX
sed -i '' -e "s/\"label\"\>/\"label\"\>$FONT_PREFIX-/g" $OVERVIEW_PAGE_PATH
fi