2020-06-20 15:30:03 +00:00
|
|
|
#!/usr/bin/env bash
|
2021-01-01 09:26:49 +00:00
|
|
|
##############################################################
|
|
|
|
#
|
|
|
|
# File: make-html.sh
|
|
|
|
#
|
|
|
|
# Description: creates html version from *.md files
|
|
|
|
#
|
|
|
|
# Usage: source make-hmtl
|
|
|
|
#
|
2021-03-10 07:39:17 +00:00
|
|
|
#### $$VERSION$$ v1.5-0-g8adca9b
|
2021-01-01 09:26:49 +00:00
|
|
|
##############################################################
|
|
|
|
|
|
|
|
# check for correct dir
|
|
|
|
if [[ ! ( -f README.html && -f README.md ) ]]; then
|
2021-01-01 10:27:54 +00:00
|
|
|
printf "Error: Can't create html, script must run where README.md and README.html is!\n"
|
2021-01-01 09:26:49 +00:00
|
|
|
|
|
|
|
else
|
|
|
|
# check if pandoc installed
|
|
|
|
if [ "$(type -t pandoc)" != "file" ]; then
|
2021-01-01 10:27:54 +00:00
|
|
|
printf "pandoc not found, skipping html generation ...\n"
|
2020-06-20 15:30:03 +00:00
|
|
|
|
2021-01-01 09:26:49 +00:00
|
|
|
else
|
|
|
|
########
|
|
|
|
# everything seems ok, start html generation
|
|
|
|
printf "Start hmtl conversion "
|
|
|
|
# create dir for html doc and index.html there
|
|
|
|
mkdir html 2>/dev/null
|
|
|
|
cp README.html html/index.html
|
|
|
|
# convert *.md files in doc to *.hmtl in html
|
|
|
|
find doc -iname "*.md" -type f -exec sh -c\
|
2021-01-05 15:17:34 +00:00
|
|
|
'printf "."; pandoc -s -f commonmark -M "title=Bashobot Documentation - ${0%.md}.html" "$0" -o "./html/$(basename ${0%.md}.html)"' {} \;
|
2021-01-01 09:26:49 +00:00
|
|
|
# html for examples dir
|
|
|
|
if [ -d "examples" ]; then
|
|
|
|
EXAMPLES="examples" # add to final conversion job
|
|
|
|
find examples -iname "*.md" -type f -exec sh -c\
|
2021-01-05 15:17:34 +00:00
|
|
|
'printf "."; pandoc -s -f commonmark -M "title=Bashobot Documentation - ${0%.md}.html" "$0" -o "${0%.md}.html"' {} \;
|
2021-01-01 09:26:49 +00:00
|
|
|
fi
|
|
|
|
# final: convert links from *.md to *.html
|
2021-01-15 17:36:09 +00:00
|
|
|
# shellcheck disable=SC2248
|
|
|
|
find README.html html ${EXAMPLES} -iname "*.html" -type f -exec sh -c\
|
2021-01-05 15:17:34 +00:00
|
|
|
'sed -i -E "s/href=\"(\.\.\/)*doc\//href=\"\1html\//g;s/href=\"(.*).md(#.*)*\"/href=\"\1.html\"/g" $0' {} \;
|
2021-01-01 09:26:49 +00:00
|
|
|
printf " Done!\n"
|
|
|
|
fi
|
2020-06-28 21:02:58 +00:00
|
|
|
fi
|