-
Notifications
You must be signed in to change notification settings - Fork 0
/
mk-website.bash
executable file
·56 lines (47 loc) · 1.44 KB
/
mk-website.bash
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
#!/bin/bash
function checkApp() {
command -v $1 >/dev/null 2>&1 || { echo $1 " is required but not installed."; exit 1; }
}
function softwareCheck() {
for APP_NAME in $@; do
checkApp $APP_NAME
done
}
function mkPage () {
nav="$1"
content="$2"
html="$3"
echo "Rendering $html"
mkpage \
"nav=$nav" \
"content=$content" \
page.tmpl > $html
}
function mkSite() {
FOLDER=$1
echo "Generating HTML content for $FOLDER"
find . -type f | grep -v .git | grep -E ".md$" | while read ITEM; do
FNAME=$(basename "$ITEM")
FOLDER=$(dirname "$ITEM")
if [ -f "$FOLDER/$FNAME" ] && [ "$FNAME" != "nav.md" ]; then
EXT=${FNAME:(-3)}
if [ "$EXT" = ".md" ]; then
HTML_FNAME=$(basename $FNAME .md).html
if [ "$HTML_FNAME" = "README.html" ]; then
HTML_FNAME=index.html
fi
# Prefer the local directory's nav.md to the root level one.
if [ -f "$FOLDER/nav.md" ]; then
mkPage "$FOLDER/nav.md" "$FOLDER/$FNAME" "$FOLDER/$HTML_FNAME"
else
mkPage "nav.md" "$FOLDER/$FNAME" "$FOLDER/$HTML_FNAME"
fi
git add "$FOLDER/$FNAME" "$FOLDER/$HTML_FNAME"
fi
fi
done
}
echo "Checking necessary software is installed"
softwareCheck mkpage
echo "Generating website"
mkSite "."