open-goverance/_scripts/format_minutes.sh

103 lines
2 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
root="$PWD"
folder_html="Minutes_html"
folder_pdf="Minutes_pdf"
# 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 "$folder_html"
mkdir "$folder_html"
2024-05-13 22:41:52 +00:00
# this folder has css and images needed
cp -R Minutes/_Templates "$folder_html/"
2024-05-13 22:41:52 +00:00
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"
2024-05-13 22:41:52 +00:00
# iterate the files
for file in {Committee,Council}_html/*.html; do
if [ -f "$file" ]; then
stripped=''${file/_html/""}
cp $file "../../$folder_html/$year/$stripped"
2024-05-13 22:41:52 +00:00
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 "$folder_pdf"
mkdir "$folder_pdf"
cd "$folder_html"
2024-05-13 22:41:52 +00:00
for file in **/*.html; do
# only deal with files
if [ -f "$file" ]; then
2024-05-13 22:41:52 +00:00
# .html => .pdf
output="../$folder_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 23:15:27 +00:00
# wait for background tasks to complete
wait $(jobs -p)
}
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