Skip to content

Instantly share code, notes, and snippets.

@nataliemarleny
Last active July 20, 2019 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nataliemarleny/b954017ea9e24d387988a279347443b3 to your computer and use it in GitHub Desktop.
Save nataliemarleny/b954017ea9e24d387988a279347443b3 to your computer and use it in GitHub Desktop.
Convert markdown files from a directory, into a directory of html files
#!/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