Convert make-council-pages.sh script to use php script

This commit is contained in:
2024-07-30 23:01:54 +10:00
parent cd9135e3bd
commit 89c87d942d
3 changed files with 13 additions and 40 deletions

View File

@@ -20,4 +20,4 @@ This is a bash script for creating a page in WordPress for each council.
If a page for a council already exists, the page will be updated instead. The source of councils for this script is the "council_names.json" file. If a page for a council already exists, the page will be updated instead. The source of councils for this script is the "council_names.json" file.
The script needs the [`jq`](https://jqlang.github.io/jq/), [`gomplate`](https://docs.gomplate.ca/), and [`wp`](https://wp-cli.org/) tools. The script needs the [`jq`](https://jqlang.github.io/jq/), [`php`](https://www.php.net/) and [`wp`](https://wp-cli.org/) tools.

View File

@@ -18,14 +18,20 @@ function create_or_update_page() {
short_name=$(echo "$council_block" | jq -r '.shortName') short_name=$(echo "$council_block" | jq -r '.shortName')
content=$(echo "$council_block" | jq -c | gomplate -d config=stdin:///in.json -f page-template) content=$(echo "$council_block" | jq -c | php php-template/main.php)
if [ $? -eq 0 ]; then
if [[ -n "$page_id" ]]; then
echo "Update page $short_name (post $page_id)"
echo "$content" | wp post update "$page_id" --post_content="$content" $WP_FLAGS -
else
echo "Create page $short_name"
echo "$content" | wp post create --post_type=page --post_title="$short_name" --post_status=publish $WP_FLAGS -
fi
if [[ -n "$page_id" ]]; then
echo "Update page $short_name (post $page_id)"
echo "$content" | wp post update "$page_id" --post_content="$content" $WP_FLAGS -
else else
echo "Create page $short_name" echo "Failed to generate page content for $short_name"
echo "$content" | wp post create --post_type=page --post_title="$short_name" --post_status=publish $WP_FLAGS -
fi fi
} }

View File

@@ -1,33 +0,0 @@
<!-- wp:paragraph -->
<p>{{ (datasource "config").councilName }}</p>
<!-- /wp:paragraph -->
{{ range $index, $element := (datasource "config").wardNames }}
<!-- wp:heading {"className":"is-style-default"} -->
<h2 class="wp-block-heading is-style-default" id="{{ $element | strings.Slug }}">{{ $element }}</h2>
<!-- /wp:heading -->
<!-- wp:group {"layout":{"type":"grid"}} -->
<div class="wp-block-group">
{{ range seq 1 5 }}
<!-- wp:group {"layout":{"type":"flex","orientation":"vertical"}} -->
<div class="wp-block-group">
<!-- wp:heading {"fontSize":"medium"} -->
<h2 class="wp-block-heading has-medium-font-size">Candidate {{.}}</h2>
<!-- /wp:heading -->
<!-- wp:image {"aspectRatio":"1","scale":"cover","style":{"color":{}}} -->
<figure class="wp-block-image"><img alt="" style="aspect-ratio:1;object-fit:cover"/></figure>
<!-- /wp:image -->
<!-- wp:paragraph -->
<p>Lorem Ipsum</p>
<!-- /wp:paragraph -->
</div>
<!-- /wp:group -->
{{end}}
</div>
<!-- /wp:group -->
{{end}}