Scripts/make_site.bash

39 lines
644 B
Bash
Executable File

#!/usr/bin/env bash
# Best practice options
set -o errexit
set -o nounset
set -o pipefail
if [[ "${TRACE-0}" == "1" ]]; then set -o xtrace; fi
if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then
echo 'Usage:
'
exit
fi
INPUT_DIR=~/notes
OUTPUT_DIR=~/public_html
pushd ~
traverse_dir() {
local dir=$1
for d in $dir; do
OUTPUT=$OUTPUT_DIR${d##$INPUT_DIR}
if [ -d "$d" ]; then
mkdir -p $OUTPUT
traverse_dir "$d/*"
elif [[ $d == *.md ]]; then
OUTPUT=${OUTPUT%.md}.html
OUTPUT=${OUTPUT// /_}
echo $OUTPUT
pandoc -f markdown -t html -o $OUTPUT "$d"
fi
done
}
traverse_dir $INPUT_DIR/\*
popd