#!/usr/bin/env bash root="$PWD" folder_html="Minutes_html" folder_pdf="Minutes_pdf" # make teh html files first function build_html() { # wipe and reset teh old html folder rm -rf "$folder_html" mkdir "$folder_html" # this folder has css and images needed cp -R Minutes/_Templates "$folder_html/" cd Minutes # loop through each year worth of data for year in */; do # skip symlinks [ -L "''${year%/}" ] && continue # exclude teh template fodler if [[ $year == *"_Templates"* ]]; then continue fi # go into the year folder cd $year # convert the Committee ones first cp ../../_scripts/md_toml/_Minutes-Committee.md.toml ./.md.toml cargo-bfom # then the council cp ../../_scripts/md_toml/_Minutes-Council.md.toml ./.md.toml cargo-bfom # cleanup rm -f .md.toml # create teh new folders where stuff is going to mkdir -p "../../$folder_html/$year/Committee" mkdir -p "../../$folder_html/$year/Council" # iterate the files for file in {Committee,Council}_html/*.html; do if [ -f "$file" ]; then stripped=''${file/_html/""} cp $file "../../$folder_html/$year/$stripped" fi done # the temp folders where teh html was created, leaving these could cause ghost artifacts rm -rf ./*_html # back up to original folder cd ../ done # return to root cd $root } function build_pdf() { # used to match ** shopt -s globstar # wipe and reset past runs rm -rf "$folder_pdf" mkdir "$folder_pdf" cd "$folder_html" for file in **/*.html; do # only deal with files if [ -f "$file" ]; then # .html => .pdf output="../$folder_pdf/${file/.html/".pdf"}" echo $output # have someplace for it to go mkdir -p $(dirname $output) wkhtmltopdf -q --enable-local-file-access --no-stop-slow-scripts "$file" "$output" 2>>../errors.log & fi done shopt -u globstar cd $root # wait for background tasks to complete wait $(jobs -p) } if [[ $1 == "html" ]]; then build_html else build_html build_pdf fi