From e4337e4b48cc414fa20900e4f6b253c8ed544b8f Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Tue, 2 Jul 2024 01:26:39 +0100 Subject: [PATCH] feat: added script to convert events to PDF --- .gitlab-ci.yml | 5 +- Events/_Templates/Logo_2024.svg | 230 +++++++++++++++++++++++++++++++ Events/_Templates/event.html | 38 +++++ Events/_Templates/main.css | 120 ++++++++++++++++ README.md | 8 +- _scripts/format_events.sh | 102 ++++++++++++++ _scripts/md_toml/_Events.md.toml | 46 +++++++ flake.nix | 9 ++ 8 files changed, 556 insertions(+), 2 deletions(-) create mode 100644 Events/_Templates/Logo_2024.svg create mode 100644 Events/_Templates/event.html create mode 100644 Events/_Templates/main.css create mode 100644 _scripts/format_events.sh create mode 100644 _scripts/md_toml/_Events.md.toml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9d9be73..48bcd78 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -19,16 +19,19 @@ pdf: - nix --extra-experimental-features 'nix-command flakes' run .#handovers - nix --extra-experimental-features 'nix-command flakes' run .#minutes - nix --extra-experimental-features 'nix-command flakes' run .#budget + - nix --extra-experimental-features 'nix-command flakes' run .#events artifacts: name: "PDFs" paths: - pdf_Handovers/ - pdf_Minutes/ - pdf_Budget/ + - pdf_Events/ - errors.log rules: - if: '$CI_PROJECT_NAMESPACE == "compsoc1/compsoc" && $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH' changes: - Committee/**/Handovers/* - Minutes/**/* - - Committee/**/Budget/* \ No newline at end of file + - Committee/**/Budget/* + - Events/**/* \ No newline at end of file diff --git a/Events/_Templates/Logo_2024.svg b/Events/_Templates/Logo_2024.svg new file mode 100644 index 0000000..0cf5682 --- /dev/null +++ b/Events/_Templates/Logo_2024.svg @@ -0,0 +1,230 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + COMP SOC + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Events/_Templates/event.html b/Events/_Templates/event.html new file mode 100644 index 0000000..328466e --- /dev/null +++ b/Events/_Templates/event.html @@ -0,0 +1,38 @@ + + + + + + + Event - {title} + + + + + + + + + + +
+ +

University of Limerick Computer Society

+ +{body} +
+ + + + + \ No newline at end of file diff --git a/Events/_Templates/main.css b/Events/_Templates/main.css new file mode 100644 index 0000000..e039c8e --- /dev/null +++ b/Events/_Templates/main.css @@ -0,0 +1,120 @@ + +/* Basic stuff */ +body { + max-width: 100ch; + margin: 0 auto; + padding: 8px; + line-height: 1.2; +} +/* To make sure the header text is always bigger than a normal h1*/ +header h1 { + font-size: 300%; +} + + +/* get these to play nicely with teh max width */ +header, main, footer, img{ + max-width: 100ch; +} + +a:link{ + color:#5bf +} +a:visited{ + color:#5bf +} + +table { + border-collapse: collapse; +} + +td, th { + border: 1px solid #999; + padding: 0.5rem; + text-align: left; +} + +li p { + margin-block-start: 0; + margin-block-end: 0; +} + +p code { + background-color: rgba(173, 173, 173, 0.26); + border-radius: 0.3em; + padding: 4px 5px 6px; +} + +pre { + max-width: 95vw; + display: block; + overflow: auto; +} + +/* navbar */ +.links ul, .breadcrumb ul { + list-style-type: none; + display: flex; + padding-left: 0; +} + +/* sticky footer */ +main { + min-height: calc(95vh - 150px); +} +footer { + min-height: 50px; +} + +/* spoilers + using https://starbeamrainbowlabs.com/blog/article.php?article=posts%2F415-pure-css-spoiler.html + as a base then using it for on hover instead of target. + Seems to work well enough for mobile as well +*/ + +.md-spoiler { + background: #333333; + border-radius: 0.2em; + color: transparent; +} +/* hover is for desktop, active for mobile*/ +.md-spoiler:hover, .md-spoiler:active { + background: transparent; + color: inherit; +} + +/* every page gets a scrollbar to stop it shifting around */ +html { + overflow-y: scroll; +} + +label, input, select { + display: table-cell; + margin-bottom: 10px; +} +/* Make hidden great again */ +[hidden] { + display: none !important; +} + + +/* Specific to handovers */ + +h1 { + color: #087581; +} + +h2 { + color: white; + background: #087581; +} + +/*h3 {*/ +/* background: #B8F4FA;*/ +/*}*/ + +#logo { + background: white; + float: right; + margin: 0 0 0 1px; +} \ No newline at end of file diff --git a/README.md b/README.md index 289c326..30b90d6 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,14 @@ Latest Minutes are available here: * [Download][0] * [Browse][2] +### Events +Latest Events are available here: +* [Download][0] +* [Browse][3] + These can be generated with ``nix run .#minutes`` [0]: https://gitlab.skynet.ie/api/v4/projects/57/jobs/artifacts/main/download?job=pdf [1]: https://gitlab.skynet.ie/compsoc1/compsoc/open-goverance/-/jobs/artifacts/main/browse/pdf_Handovers?job=pdf -[2]: https://gitlab.skynet.ie/compsoc1/compsoc/open-goverance/-/jobs/artifacts/main/browse/pdf_Minutes?job=pdf \ No newline at end of file +[2]: https://gitlab.skynet.ie/compsoc1/compsoc/open-goverance/-/jobs/artifacts/main/browse/pdf_Minutes?job=pdf +[3]: https://gitlab.skynet.ie/compsoc1/compsoc/open-goverance/-/jobs/artifacts/main/browse/pdf_Events?job=pdf \ No newline at end of file diff --git a/_scripts/format_events.sh b/_scripts/format_events.sh new file mode 100644 index 0000000..da8e411 --- /dev/null +++ b/_scripts/format_events.sh @@ -0,0 +1,102 @@ +#!/usr/bin/env bash + +root="$PWD" + +folder="Events" +folder_html="html_${folder}" +folder_pdf="pdf_${folder}" + +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 $folder + + 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 **/; do + # skip symlinks + [ -L "''${year%/}" ] && continue + + # copy in teh config for this folder + cp "../_scripts/md_toml/_${folder}.md.toml" ./.md.toml + + year_string=$(echo "$year" | cut -f1 -d"/") + sed -i -e "s/AAAAAAA/$year_string/" ./.md.toml + + # convert teh handovers + cargo-bfom + + # copy in teh relevent files + cp -R _Templates/* "./${folder}_html" + # no need to have the template in the output + rm -f ./${folder}_html/_template.md + rm -f ./${folder}_html/event.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 \ No newline at end of file diff --git a/_scripts/md_toml/_Events.md.toml b/_scripts/md_toml/_Events.md.toml new file mode 100644 index 0000000..631b783 --- /dev/null +++ b/_scripts/md_toml/_Events.md.toml @@ -0,0 +1,46 @@ + + +# How many spaces of indentation do you want? +# Defaults to 2 +# Optional +indentation = 2 + +# Optional +src = "./AAAAAAA" + +# Optional +dest= "./Events_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/event.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"] diff --git a/flake.nix b/flake.nix index 7c5e1bb..0036fe7 100644 --- a/flake.nix +++ b/flake.nix @@ -74,6 +74,15 @@ export PATH=${pkgs.lib.makeBinPath [pkgs.wkhtmltopdf bfom.defaultPackage.x86_64-linux]}:$PATH ${./_scripts/format_budget.sh} html ''; + + events = pkgs.writeShellScriptBin "format_events" '' + export PATH=${pkgs.lib.makeBinPath [pkgs.wkhtmltopdf bfom.defaultPackage.x86_64-linux]}:$PATH + ${./_scripts/format_events.sh} + ''; + events_html = pkgs.writeShellScriptBin "format_events_html" '' + export PATH=${pkgs.lib.makeBinPath [pkgs.wkhtmltopdf bfom.defaultPackage.x86_64-linux]}:$PATH + ${./_scripts/format_events.sh} html + ''; }; }); }