-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmd_htmldoc.sh
executable file
·66 lines (52 loc) · 1.96 KB
/
md_htmldoc.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
#!/usr/bin/env bash
command -v pandoc >/dev/null 2>&1 || { echo >&2 "This script requires pandoc but it's not installed. Aborting."; exit 1; }
command -v python >/dev/null 2>&1 || { echo >&2 "This script requires python but it's not installed. Aborting."; exit 1; }
ORIG=$(pwd)
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd $DIR
# make way for html
HTML_DIR=$(basename $(dirname $DIR))_htmldoc
rm --interactive=once -rf ../${HTML_DIR}
mkdir -p ../${HTML_DIR}
# mimic parent repo's directory structure in ../$HTML_DIR
PARENT_REPO_CACHED_FILES=$(cd .. && git ls-files)
echo copying directory structure...
for i in ${PARENT_REPO_CACHED_FILES[@]} ; do
FROM="../$(dirname $i)"
TO="../$HTML_DIR/$(dirname $i)"
if [[ ! -d "$TO" ]]
then
printf " %35s" "$FROM"
printf " --mkdir-->"
printf " %35s\n" "$TO"
mkdir -p "$TO"
fi
done
# discover docs in parent repo
PARENT_REPO_DOCUMENTATION=$(find .. -name .git -prune -o -name md_htmldoc -prune -o -iname "*.md" -print)
readarray -t DOC_RELEVANT<<<$($DIR/get_references.py "$PARENT_REPO_DOCUMENTATION" | tr -d '\r')
# for each documentation-relevant file
echo extracting docs...
for i in "${DOC_RELEVANT[@]}" ; do
FROM=$i
TO=${i/\.\./../$HTML_DIR}
if [[ $i == *.md ]] ; then
# generate html, replacing .md links with .html links
printf " %35s" $FROM
printf " --pandoc--> "
printf "%-35s\n" ${TO/\.md/.html}
pandoc -s "$FROM" --mathjax --filter link_filter.py -o "${TO/\.md/.html}"
else
# copy hyperlinked files
printf " %35s" $FROM
printf " ----cp----> "
printf "%-35s\n" $TO
cp "$FROM" "$TO"
fi
done
# in the parent repo, .gitignore HTML_DIR unless it is already .gitignored
touch ../.gitignore
grep -q -F "${HTML_DIR}/" ../.gitignore || echo "${HTML_DIR}/" >> ../.gitignore
# clean up any empty directories we may have created
find ../$HTML_DIR -type d -empty -delete
cd $ORIG