-
Notifications
You must be signed in to change notification settings - Fork 77
/
build.sh
executable file
·153 lines (114 loc) · 3.4 KB
/
build.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/bash
#
# Ensure in correct location
MY_PATH="`dirname \"$0\"`"
MY_PATH="`( cd \"$MY_PATH\" && pwd )`"
cd $MY_PATH
#
# Detect Pandoc version
if [[ $(pandoc --version) == pandoc\ 1* ]] ;
then
#echo 'Pandoc version 1 detected'
PANDOC_PDF_OPTION='--latex-engine'
else
#echo 'Assuming Pandoc version 2'
PANDOC_PDF_OPTION='--pdf-engine'
fi
FILTER="$1"
if [ -z "$FILTER" ]; then
echo "USAGE
To re-build all cheatsheets:
$0 --all
To re-build only certain ones, or ones that match a search criteria:
$0 python
$0 ./kickstart-backend/5-http.md
To use entr to watch for changes and rebuild a particular cheatsheet (supply
path, but omit extension):
$0 --watch topical/python
"
exit 0
fi
# Change "--all" to be no filter
if [ -n "$FILTER" ] && [ $FILTER = "--all" ]; then
FILTER=''
fi
LINKS_OUT="CHEATSHEETS.md"
function pandoc_build() {
local $*
TEMPLATE="$MY_PATH/templates/cheatsheet.latex"
IN_PATH="$IN/$name.md"
#################################
# Provides the option of selecting only certain cheatsheets
# If we specify a path instead of a search param, lets check for that too (used by entr)
if [ -n "$FILTER" ] && [[ ! $name =~ "$FILTER" ]] && [[ ! "$FILTER" -ef "$IN_PATH" ]]; then
return
fi
echo "$name -> $OUT/$name.pdf"
pandoc\
-f markdown\
"$IN_PATH"\
--variable=cohort:$COHORT\
-t latex\
--template "$TEMPLATE"\
"$PANDOC_PDF_OPTION" pdflatex\
--toc-depth 1\
-o "$OUT/$name.pdf"
if [ -x "$(command -v convert)" ]; then
convert "$OUT/$name.pdf" -background "#FFFFFF" -resize 350x -flatten "$OUT/$name.thumb.jpg"
convert -density 300 "$OUT/$name.pdf" -resize 50% -flatten "$OUT/$name.jpg"
fi
## Handle creating the LINKS.md markdown file (only when building all)
if ! [ -n "$FILTER" ]; then
echo "
### $name
[![$name PDF thumbnail](./$OUT/$name.thumb.jpg)](https://github.com/kickstartcoding/cheatsheets/raw/master/$OUT/$name.pdf)
" >> "$LINKS_OUT"
fi
}
if [ -n "$FILTER" ] && [ $FILTER = "--watch" ]; then
echo "Entering watch mode..."
ls $2.md | entr -p ./build.sh /_
exit 0
fi
## Handle creating the LINKS.md markdown file (only when building all)
if ! [ -n "$FILTER" ]; then
echo "
# Cheatsheets
Click on one of the following thumbnails to download one of our cheatsheets.
" > "$LINKS_OUT"
fi
COHORT="Cheatsheet"
IN="kickstart-fundamentals"
OUT="build/kickstart-fundamentals"
pandoc_build name="1-html-css"
pandoc_build name="2-bash-git"
pandoc_build name="3-python"
pandoc_build name="4-modules-oop"
IN="kickstart-backend"
OUT="build/kickstart-backend"
pandoc_build name="1-http"
pandoc_build name="2-django"
pandoc_build name="3-orm"
pandoc_build name="4-postgres"
IN="kickstart-frontend"
OUT="build/kickstart-frontend"
pandoc_build name="1-css"
pandoc_build name="2-javascript"
pandoc_build name="3-react"
pandoc_build name="4-components"
pandoc_build name="5-mern"
IN="kickstart-career"
OUT="build/kickstart-career"
pandoc_build name="1-algorithms"
pandoc_build name="2-industry"
IN="topical"
OUT="build/topical"
COHORT="Cheatsheet"
pandoc_build name="javascript-for-pythonistas"
pandoc_build name="python-for-js-developers"
pandoc_build name="python"
pandoc_build name="modern-html-css"
pandoc_build name="django"
pandoc_build name="cli-bash"
pandoc_build name="react-redux"
pandoc_build name="react-hooks-useeffect"