open-goverance/_scripts/format_minutes.sh

102 lines
1.9 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
root="$PWD"
# make teh html files first
2024-05-13 22:41:52 +00:00
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
}
2024-05-13 22:41:52 +00:00
function build_pdf() {
# used to match **
shopt -s globstar
2024-05-13 22:41:52 +00:00
# wipe and reset past runs
rm -rf Minutes_pdf
mkdir Minutes_pdf
2024-05-13 22:41:52 +00:00
cd Minutes_html
2024-05-13 22:41:52 +00:00
for file in **/*.html; do
# skip teh template folder
if [[ $file == *"_Templates"* ]]; then
continue
fi
2024-05-13 22:41:52 +00:00
# only deal with files
if [ -f "$file" ]; then
2024-05-13 22:41:52 +00:00
# .html => .pdf
2024-05-13 23:00:41 +00:00
output="../Minutes_pdf/${file/.html/".pdf"}"
2024-05-13 22:41:52 +00:00
echo $output
2024-05-13 22:41:52 +00:00
# have someplace for it to go
mkdir -p $(dirname $output)
2024-05-13 22:41:52 +00:00
wkhtmltopdf -q --enable-local-file-access --no-stop-slow-scripts "$file" "$output" 2>>../errors.log &
fi
done
2024-05-13 22:41:52 +00:00
shopt -u globstar
cd $root
}
2024-05-13 22:41:52 +00:00
if [[ $1 == "html" ]]; then
build_html
else
2024-05-13 22:41:52 +00:00
build_html
build_pdf
fi