forked from way-cooler/way-cooler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makedocs.sh
executable file
·67 lines (56 loc) · 1.23 KB
/
makedocs.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
#!/bin/sh
man() {
file=$1
dir=$2
lang="$(dirname $file)"
basename=$(basename $file .md)
section=${basename##*.}
mkdir -p "$dir/$lang/man$section"
echo "$file > $dir/$lang/man$section/$basename.gz"
asciidoctor -d manpage -b manpage -o - "$file" | gzip > "$dir/$lang/man$section/$basename.gz"
}
html() {
file=$1
dir=$2
basename=$(basename $file .md)
lang="$(dirname $file)"
out="$dir/$lang/$basename.html"
mkdir -p "$dir/$lang"
echo "$file > $out"
asciidoctor -o - "$file" > "$out"
}
# defaults, do all
do_man=true
do_html=true
for i in "$@"; do
case $i in
-m|--manualonly)
do_html=false
;;
-h|--htmlonly)
do_man=false
;;
*)
if [ -z "$input" ]; then
input=$i
else
output="$PWD/$i"
fi
;;
esac
done
which "asciidoctor" > /dev/null
if [ "$?" -eq 1 ]; then
echo "The asciidoctor executable is required to build man files"
exit 1
fi
if [ -z "$output" -o -z "$input" ]; then
echo "Way-cooler's documentation maker\nUsage: ./makedocs.sh [-m|--manualonly] [-h|--htmlonly] input output"
exit 1
fi
cd $input
for file in */*.md *.md; do
[ "$do_html" = true ] && html $file $output
[ "$do_man" = true ] && man $file $output
done
cd - > /dev/null