-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·120 lines (98 loc) · 2.84 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
#!/bin/bash
# builds pages from source
function build_page {
FILE_SOURCE=$1
FILE_TARGET=$2
cat $HEAD_FILE > $OUTDIR/$FILE_TARGET
echo "<!-- This is a generated file. Do not edit. -->" >> $OUTDIR/$FILE_TARGET
cat $FILE_SOURCE >> $OUTDIR/$FILE_TARGET
cat $FOOT_FILE >> $OUTDIR/$FILE_TARGET
}
function build_page_rst {
FILE_SOURCE=$1
FILE_TARGET=$2
cat $HEAD_FILE > $OUTDIR/$FILE_TARGET
echo "<!-- This is a generated file. Do not edit. -->" >> $OUTDIR/$FILE_TARGET
pandoc --to=html $FILE_SOURCE >> $OUTDIR/$FILE_TARGET
cat $FOOT_FILE >> $OUTDIR/$FILE_TARGET
}
function build_page_rst_subdir {
FILE_SOURCE=$1
FILE_TARGET=$2
./increase-link-depth.py < $HEAD_FILE > $OUTDIR/$FILE_TARGET
echo "<!-- This is a generated file. Do not edit. -->" >> $OUTDIR/$FILE_TARGET
pandoc --to=html $FILE_SOURCE >> $OUTDIR/$FILE_TARGET
./increase-link-depth.py < $FOOT_FILE >> $OUTDIR/$FILE_TARGET
}
HEAD_FILE=`pwd`/head.html
FOOT_FILE=`pwd`/foot.html
OUTDIR="build"
if [ ! -d "$OUTDIR" ]; then
mkdir $OUTDIR
echo "Creating directory $OUTDIR automatically."
echo "If you are using GitHub pages to create publish the website,"
echo "you probably want to create this directory by a dedicated script."
fi
# disable Jekyll which is not needed for out GitHub pages
touch $OUTDIR/.nojekyll
if [ ! -d "$OUTDIR" ]; then
echo "The directory $OUTDIR does not exists and it will be created for you."
mkdir $OUTDIR
fi
for FILE in `ls *.rst|grep -v foot|grep -v head`
do
build_page_rst $FILE `basename -s .rst $FILE`.html
done
for FILE in `ls *.html|grep -v foot|grep -v head`
do
build_page $FILE $FILE
done
for FILE in *.css
do
cp $FILE $OUTDIR
done
for DIR in img
do
cp -r $DIR $OUTDIR
done
for DIR in topics
do
mkdir -p $OUTDIR/$DIR
for FILE in `ls $DIR/*.rst|grep -v foot|grep -v head`
do
build_page_rst_subdir $FILE $DIR/`basename -s .rst $FILE`.html
done
for SUBDIR in data img
do
# copy only if directory exists
if [ -d "$DIR/$SUBDIR" ]; then
cp -r $DIR/$SUBDIR $OUTDIR/$DIR
fi
done
done
for DIR in resources
do
mkdir -p $OUTDIR/$DIR
for FILE in `ls $DIR/*.html $DIR/*.geojson $DIR/*.png`
do
cp $FILE $OUTDIR/$DIR
done
for SUBDIR in `ls $DIR/*`
do
if [ -d "$DIR/$SUBDIR" ]; then
cp -r $DIR/$SUBDIR $OUTDIR/$DIR
fi
done
done
# Topics index
FILES="build/topics/*.html"
TITLE="Topics"
HEAD_TEXT=""
# if this gets longer, it must go to a file
FOOT_TEXT=""
DIR="topics"
TGT_FILE=$OUTDIR/$DIR/index.html
./increase-link-depth.py < $HEAD_FILE > $TGT_FILE
echo "<!-- This is a generated file. Do not edit. -->" >> $TGT_FILE
./generate-index.py "$TITLE" "$HEAD_TEXT" "$FOOT_TEXT" $OUTDIR/$DIR/ ul ul $FILES >> $TGT_FILE
./increase-link-depth.py < $FOOT_FILE >> $TGT_FILE