open-goverance/_scripts/format_minutes.sh

104 lines
No EOL
2.2 KiB
Bash
Executable file

#!/usr/bin/env bash
root="$PWD"
# make teh html files first
function build_html(){
# wipe and reset teh old html folder
rm -rf Minutes_html
mkdir Minutes_html
# this folder has css and images needed
cp -R Minutes/_Templates Minutes_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 "../../Minutes_html/$year/Committee"
mkdir -p "../../Minutes_html/$year/Council"
# iterate the files
for file in {Committee,Council}_html/*.html; do
if [ -f "$file" ]; then
stripped=''${file/_html/""}
cp $file "../../Minutes_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 Minutes_pdf
mkdir Minutes_pdf
cd Minutes_html
for file in **/*.html; do
# skip teh template folder
if [[ $file == *"_Templates"* ]]; then
continue
fi
# only deal with files
if [ -f "$file" ]; then
# .html => .pdf
output="../Minutes_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
}
if [[ $1 == "html" ]];
then
build_html
else
build_html
build_pdf
fi