Skip to content

Instantly share code, notes, and snippets.

@jaypsan
Created August 24, 2023 20:09
Show Gist options
  • Save jaypsan/ba2978a9a235ce8e8cd0c9a1ded326f9 to your computer and use it in GitHub Desktop.
Save jaypsan/ba2978a9a235ce8e8cd0c9a1ded326f9 to your computer and use it in GitHub Desktop.
bash script for md-to-pdf Node JS CLI tool. Iterate through all folders within the script directory and, for each, concatenate all .md files and convert to PDF to ./_dist
for d in ./*/; do
# Trim last "/" from "$d
folderName=${d%*/}
# remove text until last "/"
folderName=${folderName##*/}
# checks if folder name starts with underline (_)
# yes: stop loop here
# no: continue
if [[ $folderName == _* ]]; then continue; fi
# Create _dist directory if it does not exist
mkdir -p ./_dist
# Run md-to-pdf CLI commant to convert all files within the folder
# to a single pdf file with the same name in the ./_dist directory.
cat $d/*.md | md-to-pdf > ./_dist/$folderName.pdf --config-file ./pdf_options.js
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment