From 1676c6fc25dd4340b6a72f3e4cb9b8b118fac8ac Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Sun, 19 May 2024 21:30:48 +0100 Subject: [PATCH] doc: handovers are now in a better folder and scripts have been updated to deal with it --- .gitlab-ci.yml | 6 +- Committee/_Templates/Handovers/general.html | 4 +- _scripts/format_handovers.sh | 124 ++++++++++++++------ _scripts/md_toml/_Handovers.md.toml | 6 +- 4 files changed, 96 insertions(+), 44 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 44757e4..ea5eafe 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -21,7 +21,7 @@ stages: rules: - if: '$CI_PROJECT_NAMESPACE == "compsoc1/compsoc" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' changes: - - Committee/_Handovers/**/* + - Committee/**/Handovers/* - Minutes/**/* handovers: @@ -33,8 +33,8 @@ handovers: artifacts: name: "Handovers" paths: - - Committee/_Handovers_pdf/ - - Committee/errors.log + - Handovers_pdf/ + - errors.log minutes: diff --git a/Committee/_Templates/Handovers/general.html b/Committee/_Templates/Handovers/general.html index e46453a..d5e6895 100644 --- a/Committee/_Templates/Handovers/general.html +++ b/Committee/_Templates/Handovers/general.html @@ -2,7 +2,7 @@ - + {title} @@ -16,7 +16,7 @@
- +

University of Limerick Computer Society

{body} diff --git a/_scripts/format_handovers.sh b/_scripts/format_handovers.sh index 668d1f6..a79dd97 100755 --- a/_scripts/format_handovers.sh +++ b/_scripts/format_handovers.sh @@ -1,55 +1,107 @@ #!/usr/bin/env bash -cd Committee +root="$PWD" -# cleanup the last run (if there was one) -rm -rf _Handovers_html +folder_html="Handovers_html" +folder_pdf="Handovers_pdf" -# copy in teh config for this folder -cp ../_scripts/md_toml/_Handovers.md.toml ./.md.toml +function build_html() { + # used to match ** + shopt -s globstar -cargo-bfom + # cleanup the last run (if there was one) + rm -rf "$folder_html" + mkdir "$folder_html" -## cleanup -rm -f .md.toml + cd Committee -# if the user only wants teh html tehn early return -if [[ $1 == "html" ]]; then - exit 0 -fi + root_html="$PWD" -# recursively parse _Handovers_html use wkhtmltopdf to convert to pdf -cd _Handovers_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 + # skip symlinks + [ -L "''${year%/}" ] && continue -out_folder="../_Handovers_pdf" -rm -rf "$out_folder" -for d in */; do - # skip symlinks - [ -L "''${d%/}" ] && continue - # exclude teh template fodler - if [[ $d == *"_Templates"* ]]; then - continue - fi + if ! [[ $year =~ [0-9]{4}-[0-9]{4} ]]; then + continue + fi - # create output folder - mkdir -p "$out_folder/$d" + year_string="${year/\/Handovers/""}" - # iterate the files - for file in $d*.html; do + cd "$year_string" + + # copy in teh config for this folder + cp ../../_scripts/md_toml/_Handovers.md.toml ./.md.toml + + # convert teh handovers + cargo-bfom + + # copy in teh relevent files + cp -R ../_Templates/Handovers/* ./Handovers_html + # no need to have the template in the output + rm -f ./Handovers_html/_template.md + rm -f ./Handovers_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" + + # remove teh temp folder + rm -rf ./Handovers_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 - # we need teh filename/path - stripped=''${file/.html/""} + # .html => .pdf + output="../$folder_pdf/${file/.html/".pdf"}" - echo "$out_folder/$stripped.pdf" + echo $output - # convert teh html to pdf - wkhtmltopdf -q --enable-local-file-access --no-stop-slow-scripts "$stripped.html" "$out_folder/$stripped.pdf" 2>>../errors.log & + # 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 -done -cd ../ + shopt -u globstar + cd $root -# wait for background tasks to complete -wait $(jobs -p) + # wait for background tasks to complete + wait $(jobs -p) +} + +if [[ $1 == "html" ]]; then + build_html +else + build_html + build_pdf +fi \ No newline at end of file diff --git a/_scripts/md_toml/_Handovers.md.toml b/_scripts/md_toml/_Handovers.md.toml index 1a4fac2..6beb670 100644 --- a/_scripts/md_toml/_Handovers.md.toml +++ b/_scripts/md_toml/_Handovers.md.toml @@ -6,10 +6,10 @@ indentation = 2 # Optional -src = "./_Handovers" +src = "./Handovers" # Optional -dest= "./_Handovers_html" +dest= "./Handovers_html" # html blocks you dont want to include in teh finished page # Optional @@ -24,7 +24,7 @@ html_void = [] enable = true # Set a base template # Optional -general = "./_Handovers/_Templates/general.html" +general = "../_Templates/Handovers/general.html" # Priority of the _templates to use, first one to match a markdown file is used. # An Empty array below is also valid