diff --git a/Readme.md b/Readme.md index 464e83b..ba6b0ff 100644 --- a/Readme.md +++ b/Readme.md @@ -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`](https://jqlang.github.io/jq/), [`gomplate`](https://docs.gomplate.ca/), and [`wp`](https://wp-cli.org/) tools. \ No newline at end of file +The script needs the [`jq`](https://jqlang.github.io/jq/), [`php`](https://www.php.net/) and [`wp`](https://wp-cli.org/) tools. \ No newline at end of file diff --git a/make-council-pages.sh b/make-council-pages.sh index 2d030fe..be83749 100644 --- a/make-council-pages.sh +++ b/make-council-pages.sh @@ -18,14 +18,20 @@ function create_or_update_page() { 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 - echo "Create page $short_name" - echo "$content" | wp post create --post_type=page --post_title="$short_name" --post_status=publish $WP_FLAGS - + echo "Failed to generate page content for $short_name" fi } diff --git a/page-template b/page-template deleted file mode 100644 index 34dcc6f..0000000 --- a/page-template +++ /dev/null @@ -1,33 +0,0 @@ - -
{{ (datasource "config").councilName }}
- - -{{ range $index, $element := (datasource "config").wardNames }} - -Lorem Ipsum
- -