Add support for passing media data to template

This commit is contained in:
2024-08-11 21:57:23 +10:00
parent 397fdb1ede
commit 5257ca24dc
3 changed files with 17 additions and 4 deletions

View File

@@ -25,7 +25,9 @@ function create_or_update_page() {
slug=$(echo "$council_block" | jq -r '.slug') slug=$(echo "$council_block" | jq -r '.slug')
content=$(echo "$council_block" | jq -c | php php-template/main.php --council-file "php://stdin" --candidates-file "$DATA_PATH/$slug/candidates.csv) jq -n '[inputs | { (input_filename | sub("\\.json$"; "") | sub("^.+/"; "")): . }] | reduce .[] as $item ({}; . + $item)' "$DATA_PATH"/$slug/*.json > "$DATA_PATH"/$slug/media.json
content=$(echo "$council_block" | jq -c | php php-template/main.php --council-file "php://stdin" --candidates-file "$DATA_PATH"/$slug/candidates.csv --media-file "$DATA_PATH"/$slug/media.json )
if [ $? -eq 0 ]; then if [ $? -eq 0 ]; then
@@ -40,6 +42,8 @@ function create_or_update_page() {
else else
echo "Failed to generate page content for $short_name" echo "Failed to generate page content for $short_name"
fi fi
rm "$DATA_PATH"/$slug/media.json
} }
# Read council data # Read council data

View File

@@ -1,7 +1,7 @@
<?php <?php
require_once "page_renderer.php"; require_once "page_renderer.php";
$options = getopt("", ["council-file:", "candidates-file:"]); $options = getopt("", ["council-file:", "candidates-file:", "media-file:"]);
if (isset($options['council-file'])) { if (isset($options['council-file'])) {
$councilFileContents = file_get_contents($options['council-file']); $councilFileContents = file_get_contents($options['council-file']);
@@ -50,8 +50,17 @@ if (empty($candidateData)) {
error_log("Failed to load any candidates for " . $councilData['shortName']); error_log("Failed to load any candidates for " . $councilData['shortName']);
} }
if (isset($options['media-file'])) {
$mediaFileContents = file_get_contents($options['media-file']);
} else {
error_log("Error: Missing required option '--media-file'.");
exit(1);
}
$mediaData = json_decode($mediaFileContents, true);
$renderer = new SPLPageRenderer(); $renderer = new SPLPageRenderer();
$pageContent = $renderer->renderCouncilPage($councilData, $candidateData); $pageContent = $renderer->renderCouncilPage($councilData, $candidateData, $mediaData);
if ($pageContent === null) { if ($pageContent === null) {
exit(2); exit(2);
} }

View File

@@ -1,7 +1,7 @@
<?php <?php
class SPLPageRenderer { class SPLPageRenderer {
public function renderCouncilPage($config, $candidates) { public function renderCouncilPage($config, $candidates, $media) {
ob_start(); ob_start();
$didError = false; $didError = false;