Compare commits
8 Commits
8a1983a0f3
...
d04602332f
| Author | SHA1 | Date | |
|---|---|---|---|
| d04602332f | |||
| 78cb6bf077 | |||
| acb1c47d68 | |||
| db1a86c0b9 | |||
| f8fabe6dc1 | |||
| 7d613f7f0d | |||
| 295cb0e66d | |||
| 6d8e023807 |
32
bulk-upload-media.sh
Normal file
32
bulk-upload-media.sh
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Tries to upload media to wordpress and stores a json file with the ID and url of the media.
|
||||||
|
|
||||||
|
# This script uses the jq, and wp commands, make sure they are installed before running this script.
|
||||||
|
|
||||||
|
# Additionally, make sure the wp-cli/restful package is installed in the wp command (via "wp package install wp-cli/restful")
|
||||||
|
|
||||||
|
# Controls the flags that are passed to every usage of the wp command.
|
||||||
|
WP_FLAGS="--allow-root --path=/var/www/html"
|
||||||
|
|
||||||
|
path="$1"
|
||||||
|
|
||||||
|
wp package install wp-cli/restful $WP_FLAGS
|
||||||
|
|
||||||
|
if test -d "$path"; then
|
||||||
|
echo "Found $path, starting upload."
|
||||||
|
for file in "$path"/*.jpg; do
|
||||||
|
./upload-media.sh "$file"
|
||||||
|
done
|
||||||
|
for file in "$path"/*.jpeg; do
|
||||||
|
./upload-media.sh "$file"
|
||||||
|
done
|
||||||
|
for file in "$path"/*.png; do
|
||||||
|
./upload-media.sh "$file"
|
||||||
|
done
|
||||||
|
for file in "$path"/*.gif; do
|
||||||
|
./upload-media.sh "$file"
|
||||||
|
done
|
||||||
|
else
|
||||||
|
echo "Could not find $path"
|
||||||
|
fi
|
||||||
@@ -52,9 +52,13 @@ data=$(cat "$COUNCILS_FILE")
|
|||||||
# Get all page IDs in one go because the wp command is pretty slow
|
# Get all page IDs in one go because the wp command is pretty slow
|
||||||
wp_posts=$(wp post list --post_type=page --format=json $WP_FLAGS)
|
wp_posts=$(wp post list --post_type=page --format=json $WP_FLAGS)
|
||||||
|
|
||||||
|
selected_council="$1"
|
||||||
|
|
||||||
# Iterate over JSON objects
|
# Iterate over JSON objects
|
||||||
jq -c '.[] | .' <<< "$data" | while IFS=' ' read -r council_block; do
|
jq -c '.[] | .' <<< "$data" | while IFS=' ' read -r council_block; do
|
||||||
short_name=$(echo "$council_block" | jq -r '.shortName')
|
short_name=$(echo "$council_block" | jq -r '.shortName')
|
||||||
page_id=$(echo $wp_posts | jq '.[] | select(.post_title == "'"$short_name"'") | .ID' | head -n 1)
|
page_id=$(echo $wp_posts | jq '.[] | select(.post_title == "'"$short_name"'") | .ID' | head -n 1)
|
||||||
|
if [ ! "$selected_council" ] || [ "$short_name" = "$selected_council" ]; then
|
||||||
create_or_update_page "$council_block" "$page_id"
|
create_or_update_page "$council_block" "$page_id"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
@@ -9,8 +9,9 @@
|
|||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
|
||||||
<?php foreach ($config['wardNames'] as $index => $wardName): ?>
|
<?php foreach ($config['wardNames'] as $index => $wardName): ?>
|
||||||
<!-- wp:heading {"className":"is-style-default"} -->
|
<!-- wp:heading {"level":3,"className":"is-style-default"} -->
|
||||||
<h2 class="wp-block-heading is-style-default" id="<?php echo strtolower(str_replace(' ', '-', $wardName)); ?>"><?php echo $wardName; ?></h2>
|
<?php $wardSlug = strtolower(str_replace(' ', '-', $wardName)); ?>
|
||||||
|
<h3 class="wp-block-heading is-style-default" id="<?php echo $wardSlug; ?>"><a style="text-decoration: none;" href="#<?php echo $wardSlug; ?>"><?php echo $wardName; ?></a></h3>
|
||||||
<!-- /wp:heading -->
|
<!-- /wp:heading -->
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
@@ -18,23 +19,38 @@ $wardCandidates = array_filter($candidates, function ($candidate) use ($wardName
|
|||||||
return isset($candidate["Ward"]) && $candidate["Ward"] === $wardName;
|
return isset($candidate["Ward"]) && $candidate["Ward"] === $wardName;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
usort($wardCandidates, function($a, $b) {
|
||||||
|
if ($a == $b) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return (((int) $a) < ((int) $b)) ? 1 : -1;
|
||||||
|
});
|
||||||
|
|
||||||
if (count($wardCandidates) == 0) continue;
|
if (count($wardCandidates) == 0) continue;
|
||||||
?>
|
?>
|
||||||
<!-- wp:group {"layout":{"type":"grid","columnCount":3}} -->
|
<!-- wp:group {"layout":{"type":"grid","columnCount":3}} -->
|
||||||
<div class="wp-block-group">
|
<div class="wp-block-group">
|
||||||
<?php foreach ($wardCandidates as $index => $candidate): ?>
|
<?php foreach ($wardCandidates as $index => $candidate): ?>
|
||||||
<!-- wp:group {"layout":{"type":"flex","orientation":"vertical"}} -->
|
<!-- wp:group {"layout":{"type":"flex","orientation":"vertical","justifyContent":"center"}} -->
|
||||||
<div class="wp-block-group">
|
<div class="wp-block-group">
|
||||||
<!-- wp:heading {"fontSize":"medium"} -->
|
<?php
|
||||||
<h2 class="wp-block-heading has-medium-font-size"><?php echo $candidate['Candidate Name']; ?></h2>
|
if (isset($media[$candidate['Picture']])) {
|
||||||
<!-- /wp:heading -->
|
$candidate_image = $media[$candidate['Picture']];
|
||||||
|
} else {
|
||||||
|
$candidate_image = $media['default.png'];
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
<!-- wp:image {"aspectRatio":"1","scale":"cover","style":{"color":{}}} -->
|
<!-- wp:image {"id":<?php echo $candidate_image['id']; ?>,"aspectRatio":"1","scale":"cover","style":{"color":{}}} -->
|
||||||
<figure class="wp-block-image"><img alt="" style="aspect-ratio:1;object-fit:cover"/></figure>
|
<figure class="wp-block-image"><img src="<?php echo $candidate_image['url']; ?>" alt="" class="wp-image-<?php echo $candidate_image['id']; ?>" style="aspect-ratio:1;object-fit:cover"/></figure>
|
||||||
<!-- /wp:image -->
|
<!-- /wp:image -->
|
||||||
|
|
||||||
|
<!-- wp:heading {"fontSize":"medium"} -->
|
||||||
|
<h2 class="wp-block-heading has-medium-font-size"><strong><?php echo $candidate['Candidate Name']; ?></strong></h2>
|
||||||
|
<!-- /wp:heading -->
|
||||||
|
|
||||||
<!-- wp:paragraph -->
|
<!-- wp:paragraph -->
|
||||||
<p>Lorem Ipsum</p>
|
<p><?php echo str_repeat("✔️", $candidate['Rating']); ?></p>
|
||||||
<!-- /wp:paragraph -->
|
<!-- /wp:paragraph -->
|
||||||
</div>
|
</div>
|
||||||
<!-- /wp:group -->
|
<!-- /wp:group -->
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ if test -f "$media_path"; then
|
|||||||
else
|
else
|
||||||
echo "Could not find $media_path.json, uploading media!"
|
echo "Could not find $media_path.json, uploading media!"
|
||||||
id=$(wp media import "$media_path" --porcelain $WP_FLAGS)
|
id=$(wp media import "$media_path" --porcelain $WP_FLAGS)
|
||||||
url=$(wp rest attachment get "$id" --field=source_url $WP_FLAGS)
|
url=$(wp rest attachment get "$id" --field=source_url $WP_FLAGS | sed 's/127.0.0.1/streetspeoplelove.org/')
|
||||||
jq -n --arg id $id --arg url "$url" '{"id": $id, "url": $url}' > "$media_path.json"
|
jq -n --arg id $id --arg url "$url" '{"id": $id, "url": $url}' > "$media_path.json"
|
||||||
cat "$media_path.json"
|
cat "$media_path.json"
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user