Last active
February 28, 2019 03:21
-
-
Save dfdgsdfg/73af0df10162ae064002bf79a1864b07 to your computer and use it in GitHub Desktop.
Pandoc md to docx every file in folder bashshell
This file contains hidden or 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 | |
echo "==========================" | |
echo "YOU NEED TO INSTALL PANDOC" | |
echo "==========================" | |
SRC_DIR='./src' | |
DIST_DIR='./dist' | |
files=($(find ${SRC_DIR} -type f -name '*.md')) | |
[ -d "${DIST_DIR}" ] || mkdir ${DIST_DIR} | |
for file in ${files[*]} | |
do | |
file_name=(${file##*/}) | |
echo $file $file_name | |
# readarray -td/ paths <<< "$file"; declare -p paths; // macos does not work | |
IFS='/' read -r -a paths <<< "$file"; | |
paths_depth=${#paths[@]} | |
echo ${paths[*]} $paths_depth | |
if [ ${paths_depth} -gt "3" ] | |
then | |
sub_dir=${paths[2]} | |
echo $sub_dir | |
[ -d "$DIST_DIR/$sub_dir" ] || mkdir ${DIST_DIR}/${sub_dir} | |
out_dir=(${DIST_DIR}/${sub_dir}) | |
echo $out_dir | |
else | |
out_dir=(${DIST_DIR}) | |
echo $out_dir | |
fi | |
pandoc $file -f markdown -t docx -o ${out_dir}/${file_name}.docx | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment