2024-05-20 01:44:50 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
root="$PWD"
|
|
|
|
|
2024-08-10 22:40:35 +00:00
|
|
|
folder="Budget"
|
|
|
|
folder_lower="budget"
|
|
|
|
folder_html="html_${folder_lower}"
|
|
|
|
folder_pdf="pdf_${folder_lower}"
|
2024-05-20 01:44:50 +00:00
|
|
|
|
|
|
|
function build_html() {
|
|
|
|
# used to match **
|
|
|
|
shopt -s globstar
|
|
|
|
|
|
|
|
# cleanup the last run (if there was one)
|
|
|
|
rm -rf "$folder_html"
|
|
|
|
mkdir "$folder_html"
|
|
|
|
|
|
|
|
cd Committee
|
|
|
|
|
|
|
|
root_html="$PWD"
|
|
|
|
|
|
|
|
# loop through each year worth of data
|
|
|
|
# the globbing is to only get ones that have a handover folder
|
|
|
|
for year in **/$folder; do
|
|
|
|
# skip symlinks
|
|
|
|
[ -L "''${year%/}" ] && continue
|
|
|
|
|
|
|
|
if ! [[ $year =~ [0-9]{4}-[0-9]{4} ]]; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
year_string=$(echo "$year" | cut -f1 -d"/")
|
|
|
|
|
|
|
|
cd "$year_string"
|
|
|
|
|
|
|
|
# copy in teh config for this folder
|
|
|
|
cp "../../_scripts/md_toml/_${folder}.md.toml" ./.md.toml
|
|
|
|
|
|
|
|
# convert teh handovers
|
|
|
|
cargo-bfom
|
|
|
|
|
|
|
|
# copy in teh relevent files
|
|
|
|
cp -R ../_Templates/$folder/* "./$folder_html"
|
|
|
|
# no need to have the template in the output
|
|
|
|
rm -f ./$folder_html/_template.md
|
|
|
|
rm -f ./$folder_html/general.html
|
|
|
|
rm -f .md.toml
|
|
|
|
|
|
|
|
# make the final folder
|
2024-08-10 22:40:35 +00:00
|
|
|
mkdir -p "$root/$folder_html/${folder_html}"
|
2024-05-20 01:44:50 +00:00
|
|
|
|
|
|
|
# copy everything to teh final folder
|
2024-08-10 22:40:35 +00:00
|
|
|
cp -R ./$folder_html/* "$root/${folder_html}$year_string"
|
2024-05-20 01:44:50 +00:00
|
|
|
|
|
|
|
# remove teh temp folder
|
|
|
|
rm -rf "./$folder_html"
|
|
|
|
|
|
|
|
# return to root
|
|
|
|
cd "$root_html"
|
|
|
|
done
|
|
|
|
|
|
|
|
# undo the globbing
|
|
|
|
shopt -u globstar
|
|
|
|
|
|
|
|
|
|
|
|
# back 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
|