Last active
July 20, 2019 18:16
-
-
Save nataliemarleny/b954017ea9e24d387988a279347443b3 to your computer and use it in GitHub Desktop.
Convert markdown files from a directory, into a directory of html files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -eu -o pipefail | |
markdown_dir="${1:-markdown}" | |
html_dir="${2:-html}" | |
MARKED_EXEC="${MARKED_EXEC:-yarn exec marked}" | |
sanitise() { | |
cat | sed 's#\.md#.html#g' | |
} | |
for f_input in $(find "${markdown_dir}" -type f); do | |
f_strip_dir="${f_input#*/}" | |
f_strip_ext="${f_strip_dir%.*}" | |
f_output="${html_dir}/${f_strip_ext}.html" | |
f_output_dir="$(dirname "${f_output}")" | |
# make sure target directory exists | |
mkdir -p "${f_output_dir}" | |
# transform markdown to html | |
cat "${f_input}" | sanitise | ${MARKED_EXEC} > "${f_output}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment