Add batch import script

This commit is contained in:
thePR0M3TH3AN
2025-06-17 21:08:18 -04:00
parent 48c4bed936
commit fe1f778dba
5 changed files with 46 additions and 6 deletions

1
.gitignore vendored
View File

@@ -15,3 +15,4 @@ tmp*/
Thumbs.db Thumbs.db
*~ *~
*.swp *.swp
imports/*.json

View File

@@ -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`. 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/<subdomain>` directory. 3. Host the generated `host/<subdomain>` 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 ## Hosting Options
The folder under `host/<subdomain>` contains all of the files needed to serve The folder under `host/<subdomain>` contains all of the files needed to serve
the flyer as a static website. A few easy ways to make it publicly accessible the flyer as a static website. A few easy ways to make it publicly accessible

0
imports/.gitkeep Normal file
View File

View File

@@ -15,10 +15,11 @@ done
CONFIG_PATH="src/config.json" CONFIG_PATH="src/config.json"
FROM_PDF="" FROM_PDF=""
NON_INTERACTIVE=0
usage() { usage() {
echo "Usage: $0 [-c config_path] [--from-pdf PDF]" echo "Usage: $0 [-c config_path] [--from-pdf PDF] [--no-interaction]"
echo "Create and deploy a flyer based on config.json." echo "Create and deploy a flyer based on config.json."
exit 1 exit 1
} }
@@ -33,6 +34,10 @@ while [[ $# -gt 0 ]]; do
FROM_PDF="$2" FROM_PDF="$2"
shift 2 shift 2
;; ;;
-n|--no-interaction)
NON_INTERACTIVE=1
shift
;;
-h|--help) -h|--help)
usage usage
;; ;;
@@ -89,10 +94,12 @@ update_config_from_pdf() {
rm -rf "$tmpdir" rm -rf "$tmpdir"
} }
if [[ -n "$FROM_PDF" ]]; then if [[ $NON_INTERACTIVE -eq 0 ]]; then
update_config_from_pdf if [[ -n "$FROM_PDF" ]]; then
else update_config_from_pdf
update_config_interactive else
update_config_interactive
fi
fi fi
# Regenerate QR codes based on the updated configuration # Regenerate QR codes based on the updated configuration

21
src/import_from_json.sh Executable file
View File

@@ -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