feat: new script to generate PDF's for the budget

This commit is contained in:
silver 2024-05-20 02:44:50 +01:00
parent 180736e69b
commit ac86f81192
Signed by: silver
GPG key ID: 54E2C71918E93B74
11 changed files with 631 additions and 41 deletions

108
_scripts/format_budget.sh Executable file
View file

@ -0,0 +1,108 @@
#!/usr/bin/env bash
root="$PWD"
folder="Budget"
folder_html="Budget_html"
folder_pdf="Budget_pdf"
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
mkdir -p "$root/$folder_html/$year_string"
# copy everything to teh final folder
cp -R ./$folder_html/* "$root/$folder_html/$year_string"
# 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

View file

@ -2,8 +2,9 @@
root="$PWD"
folder_html="Handovers_html"
folder_pdf="Handovers_pdf"
folder="Handovers"
folder_html="${folder}_html"
folder_pdf="${folder}_pdf"
function build_html() {
# used to match **
@ -19,7 +20,7 @@ function build_html() {
# loop through each year worth of data
# the globbing is to only get ones that have a handover folder
for year in **/Handovers; do
for year in **/$folder; do
# skip symlinks
[ -L "''${year%/}" ] && continue
@ -27,31 +28,31 @@ function build_html() {
continue
fi
year_string="${year/\/Handovers/""}"
year_string=$(echo "$year" | cut -f1 -d"/")
cd "$year_string"
# copy in teh config for this folder
cp ../../_scripts/md_toml/_Handovers.md.toml ./.md.toml
cp "../../_scripts/md_toml/_${folder}.md.toml" ./.md.toml
# convert teh handovers
cargo-bfom
# copy in teh relevent files
cp -R ../_Templates/Handovers/* ./Handovers_html
cp -R ../_Templates/$folder/* "./$folder_html"
# no need to have the template in the output
rm -f ./Handovers_html/_template.md
rm -f ./Handovers_html/general.html
rm -f ./$folder_html/_template.md
rm -f ./$folder_html/general.html
rm -f .md.toml
# make the final folder
mkdir -p "$root/$folder_html/$year_string"
# copy everything to teh final folder
cp -R ./Handovers_html/* "$root/$folder_html/$year_string"
cp -R ./$folder_html/* "$root/$folder_html/$year_string"
# remove teh temp folder
rm -rf ./Handovers_html
rm -rf "./$folder_html"
# return to root
cd "$root_html"

View file

@ -0,0 +1,46 @@
# How many spaces of indentation do you want?
# Defaults to 2
# Optional
indentation = 2
# Optional
src = "./Budget"
# Optional
dest= "./Budget_html"
# html blocks you dont want to include in teh finished page
# Optional
html_void = []
[template]
# Templates are hjtml files that teh generated markdown is insereted into.
# There are several options on how this is carried out.
# enable templating
# Optional
enable = true
# Set a base template
# Optional
general = "../_Templates/Budget/general.html"
# Priority of the _templates to use, first one to match a markdown file is used.
# An Empty array below is also valid
# general: use the general file specified above, if it exists.
# ajacent: check if there is a template file with the same name as the markdown file ajacent to the markdown file.
# ./src/exasmple.md
# ./src/example.html
# folder: a html file with the same name of the folder that the md resides in.
# ./src/blog/blog.html
# ./src/blog/post1.md
# default: use an inbuilt html5 template
# Optional
order = ["ajacent", "general", "folder", "default"]