From fe1f778dba323e68725dca7ebe5a2995adf1fdee Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Tue, 17 Jun 2025 21:08:18 -0400 Subject: [PATCH] Add batch import script --- .gitignore | 1 + README.md | 11 +++++++++++ imports/.gitkeep | 0 src/create_flyer.sh | 19 +++++++++++++------ src/import_from_json.sh | 21 +++++++++++++++++++++ 5 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 imports/.gitkeep create mode 100755 src/import_from_json.sh diff --git a/.gitignore b/.gitignore index 3df045c..a1f2d0e 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ tmp*/ Thumbs.db *~ *.swp +imports/*.json diff --git a/README.md b/README.md index 477d759..482f9a0 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,17 @@ Additional documentation is available in the `src/` directory; see [src/README.m 2. Run `./src/create_flyer.sh` and follow the prompts, or use `./src/create_flyer.sh --from-pdf path/to/form.pdf`. 3. Host the generated `host/` directory. +## Batch Import +Place configuration files in an `imports/` directory at the project root. Run + +```bash +./src/import_from_json.sh +``` + +Each JSON file is copied to `src/config.json` and processed with +`create_flyer.sh --no-interaction`. Existing folders under `host/` with the +same subdomain are removed before new files are written. + ## Hosting Options The folder under `host/` contains all of the files needed to serve the flyer as a static website. A few easy ways to make it publicly accessible diff --git a/imports/.gitkeep b/imports/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/create_flyer.sh b/src/create_flyer.sh index cfb2757..557e08c 100755 --- a/src/create_flyer.sh +++ b/src/create_flyer.sh @@ -15,10 +15,11 @@ done CONFIG_PATH="src/config.json" FROM_PDF="" +NON_INTERACTIVE=0 usage() { - echo "Usage: $0 [-c config_path] [--from-pdf PDF]" - echo "Create and deploy a flyer based on config.json." + echo "Usage: $0 [-c config_path] [--from-pdf PDF] [--no-interaction]" + echo "Create and deploy a flyer based on config.json." exit 1 } @@ -33,6 +34,10 @@ while [[ $# -gt 0 ]]; do FROM_PDF="$2" shift 2 ;; + -n|--no-interaction) + NON_INTERACTIVE=1 + shift + ;; -h|--help) usage ;; @@ -89,10 +94,12 @@ update_config_from_pdf() { rm -rf "$tmpdir" } -if [[ -n "$FROM_PDF" ]]; then - update_config_from_pdf -else - update_config_interactive +if [[ $NON_INTERACTIVE -eq 0 ]]; then + if [[ -n "$FROM_PDF" ]]; then + update_config_from_pdf + else + update_config_interactive + fi fi # Regenerate QR codes based on the updated configuration diff --git a/src/import_from_json.sh b/src/import_from_json.sh new file mode 100755 index 0000000..7d4d344 --- /dev/null +++ b/src/import_from_json.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +set -euo pipefail + +IMPORT_DIR="imports" +shopt -s nullglob +files=("$IMPORT_DIR"/*.json) + +if [[ ${#files[@]} -eq 0 ]]; then + echo "No JSON files found in $IMPORT_DIR" + exit 0 +fi + +for json in "${files[@]}"; do + echo "Processing $json" + cp "$json" src/config.json + subdomain=$(jq -r '.subdomain' "$json") + dest="host/$subdomain" + rm -rf "$dest" + ./src/create_flyer.sh --no-interaction +done