-
Notifications
You must be signed in to change notification settings - Fork 0
/
shorten
executable file
·92 lines (81 loc) · 5.95 KB
/
shorten
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
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
usage="shorten -b <bookname> -i <inputfile>"
# Get command line arguments
while getopts b:i:h flag
do
case "${flag}" in
b) book=${OPTARG} ;;
i) input_file=${OPTARG} ;;
h) echo $usage; exit 0 ;;
*) echo "Unknown flag '${flag}'"; exit 1 ;;
esac
done
# List additional lib/recipes here
case "${book}" in
american-government) dest="${DIR}/data/american-government/short" && script="${DIR}/lib/recipes/american-government/shorten";;
ap-history) dest="${DIR}/data/ap-history/short" && script="${DIR}/lib/recipes/ap-history/shorten";;
biology) dest="${DIR}/data/biology/short" && script="${DIR}/lib/recipes/biology/shorten";;
calculus) dest="${DIR}/data/calculus/short" && script="${DIR}/lib/recipes/calculus/shorten";;
chemistry) dest="${DIR}/data/chemistry/short" && script="${DIR}/lib/recipes/chemistry/shorten";;
statistics) dest="${DIR}/data/statistics/short" && script="${DIR}/lib/recipes/statistics/shorten";;
pl-psychology) dest="${DIR}/data/pl-psychology/short" && script="${DIR}/lib/recipes/pl-psychology/shorten";;
microbiology) dest="${DIR}/data/microbiology/short" && script="${DIR}/lib/recipes/microbiology/shorten";;
precalculus) dest="${DIR}/data/precalculus/short" && script="${DIR}/lib/recipes/precalculus/shorten";;
precalculus-coreq) dest="${DIR}/data/college-algebra-coreq/short" && script="${DIR}/lib/recipes/precalculus-coreq/shorten";;
sociology) dest="${DIR}/data/sociology/short" && script="${DIR}/lib/recipes/sociology/shorten";;
u-physics) dest="${DIR}/data/u-physics/short" && script="${DIR}/lib/recipes/u-physics/shorten";;
economics) dest="${DIR}/data/economics/short" && script="${DIR}/lib/recipes/economics/shorten";;
finance) dest="${DIR}/data/finance/short" && script="${DIR}/lib/recipes/finance/shorten";;
english-composition) dest="${DIR}/data/english-composition/short" && script="${DIR}/lib/recipes/english-composition/shorten";;
microbiology) dest="${DIR}/data/microbiology/short" && script="${DIR}/lib/recipes/microbiology/shorten";;
anatomy) dest="${DIR}/data/anatomy/short" && script="${DIR}/lib/recipes/anatomy/shorten";;
bca) dest="${DIR}/data/bca/short" && script="${DIR}/lib/recipes/bca/shorten";;
computer-science) dest="${DIR}/data/computer-science/short" && script="${DIR}/lib/recipes/computer-science/shorten";;
political-science) dest="${DIR}/data/political-science/short" && script="${DIR}/lib/recipes/political-science/shorten";;
ap-biology) dest="${DIR}/data/ap-biology/short" && script="${DIR}/lib/recipes/ap-biology/shorten";;
college-physics) dest="${DIR}/data/college-physics/short" && script="${DIR}/lib/recipes/college-physics/shorten";;
college-physics-2e) dest="${DIR}/data/college-physics-2e/short" && script="${DIR}/lib/recipes/college-physics-2e/shorten";;
astronomy) dest="${DIR}/data/astronomy/short" && script="${DIR}/lib/recipes/astronomy/shorten";;
ap-physics) dest="${DIR}/data/ap-physics/short" && script="${DIR}/lib/recipes/ap-physics/shorten";;
ap-physics-2e) dest="${DIR}/data/ap-physics-2e/short" && script="${DIR}/lib/recipes/ap-physics-2e/shorten";;
history) dest="${DIR}/data/history/short" && script="${DIR}/lib/recipes/history/shorten";;
dev-math) dest="${DIR}/data/prealgebra/short" && script="${DIR}/lib/recipes/dev-math/shorten";;
hs-physics) dest="${DIR}/data/hs-physics/short" && script="${DIR}/lib/recipes/hs-physics/shorten";;
college-success) dest="${DIR}/data/college-success/short" && script="${DIR}/lib/recipes/college-success/shorten";;
hs-college-success) dest="${DIR}/data/hs-college-success/short" && script="${DIR}/lib/recipes/hs-college-success/shorten";;
psychology) dest="${DIR}/data/psychology/short" && script="${DIR}/lib/recipes/psychology/shorten";;
entrepreneurship) dest="${DIR}/data/entrepreneurship/short" && script="${DIR}/lib/recipes/entrepreneurship/shorten";;
nursing-external) dest="${DIR}/data/nursing-external/short" && script="${DIR}/lib/recipes/nursing-external/shorten";;
intro-business) dest="${DIR}/data/intro-business/short" && script="${DIR}/lib/recipes/intro-business/shorten";;
principles-management) dest="${DIR}/data/principles-management/short" && script="${DIR}/lib/recipes/principles-management/shorten";;
business-ethics) dest="${DIR}/data/business-ethics/short" && script="${DIR}/lib/recipes/business-ethics/shorten";;
accounting) dest="${DIR}/data/accounting/short" && script="${DIR}/lib/recipes/accounting/shorten";;
philosophy) dest="${DIR}/data/philosophy/short" && script="${DIR}/lib/recipes/philosophy/shorten";;
pl-economics) dest="${DIR}/data/pl-microeconomics/short" && script="${DIR}/lib/recipes/pl-economics/shorten";;
pl-u-physics) dest="${DIR}/data/pl-u-physics/short" && script="${DIR}/lib/recipes/pl-u-physics/shorten";;
world-history) dest="${DIR}/data/world-history/short" && script="${DIR}/lib/recipes/world-history/shorten";;
marketing) dest="${DIR}/data/marketing/short" && script="${DIR}/lib/recipes/marketing/shorten";;
organic-chemistry) dest="${DIR}/data/organic-chemistry/short" && script="${DIR}/lib/recipes/organic-chemistry/shorten";;
contemporary-math) dest="${DIR}/data/contemporary-math/short" && script="${DIR}/lib/recipes/contemporary-math/shorten";;
python) dest="${DIR}/data/python/short" && script="${DIR}/lib/recipes/python/shorten";;
nursing-internal) dest="${DIR}/data/nursing-internal/short" && script="${DIR}/lib/recipes/nursing-internal/shorten";;
*) echo "Unknown book '${book}'"; exit 1;;
esac
# Call the shorten script
echo "Shortening ..."
if [ ! -d $dest ]
then
mkdir $dest
fi
$script --input $input_file --output $dest/assembled.xhtml
# Bake shortened book with kitchen
if [ -e $DIR/lib/recipes/$book/bake ]
then
echo "Baking with kitchen ..."
./bake -b $book -i $dest/assembled.xhtml -o $dest/kitchen-baked.xhtml
# Normalize the kitchen baked book
ruby scripts/normalize $dest/kitchen-baked.xhtml
else
echo "Cannot bake with kitchen because lib/recipes/${book}/bake does not exist."
fi