Create initial template for council pages
This commit is contained in:
@@ -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.
|
||||
|
||||
The script needs the `jq` and `wp` tools.
|
||||
The script needs the [`jq`](https://jqlang.github.io/jq/), [`gomplate'](https://docs.gomplate.ca/), and [`wp`](https://wp-cli.org/) tools.
|
||||
@@ -1,10 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This script uses the wp and jq commands, make sure they are installed before running this script.
|
||||
# This script uses the jq, wp, and gomplate commands, make sure they are installed before running this script.
|
||||
|
||||
# The council_names.json file must contain a list of objects (one for each council).
|
||||
# Each object must have a "shortName" field and a "wardNames" field.
|
||||
# Each object must have the following fields: "shortName", "councilName", and "wardNames"
|
||||
# The "shortName" field must be a string.
|
||||
# The "councilName" field must be a string.
|
||||
# The "wardNames" field must be a list of strings.
|
||||
JSON_FILE="council_names.json"
|
||||
|
||||
@@ -17,15 +18,14 @@ function create_or_update_page() {
|
||||
|
||||
short_name=$(echo "$council_block" | jq -r '.shortName')
|
||||
|
||||
# TODO: Generate better content! This just outputs the name of each ward.
|
||||
content=$(echo "$council_block" | jq -r '.wardNames | .[]')
|
||||
content=$(echo "$council_block" | jq -c | gomplate -d config=stdin:///in.json -f page-template)
|
||||
|
||||
if [[ -n "$page_id" ]]; then
|
||||
echo "Update page $short_name (post $page_id)"
|
||||
wp post update "$page_id" --post_content="$content" $WP_FLAGS
|
||||
echo "$content" | wp post update "$page_id" --post_content="$content" $WP_FLAGS -
|
||||
else
|
||||
echo "Create page $short_name"
|
||||
wp post create --post_type=page --post_title="$short_name" --post_status=publish --post_content="$content" $WP_FLAGS
|
||||
echo "$content" | wp post create --post_type=page --post_title="$short_name" --post_status=publish $WP_FLAGS -
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
33
page-template
Normal file
33
page-template
Normal file
@@ -0,0 +1,33 @@
|
||||
<!-- 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}}
|
||||
Reference in New Issue
Block a user