Platform Components
The platform has two primary components: WordPress and Next.js. WordPress is used for layout and content while Next.js serves up the content in a React.js single page application.
WordPress
WordPress instance - WordPress contains HTML contents that have been laid out in the Block Editor using custom blocks developed for digital.gov.bc.ca specific look and feel.
Custom WordPress plugin - the plugin contains custom blocks for the use in the block editor as well as other features in the following files:
./editor.js - this setups up the “Preview on digital.gov.bc.ca” button in the block editor for previewing the contents on digital.gov.bc.ca
./custom.php - this file performs a number of functions:
Enqueues JavaScript files for the editor (jQuery - for setting up “Preview on digital.gov.bc.ca” button, editor.js, block_extensions.js)
Creates custom roles for workflow management within WordPress
Creates custom capabilities and adds those capabilities to custom roles
Filters the list of blocks that appears in the block editor - this is done to restrict the degrees of freedom available to the content editors - to a few core blocks and custom blocks developed for digital.gov.bc.ca
Sets up custom post types
Sets up default templates for post types
assets/block_extensions.js - this file contains extensions to core WordPress blocks:
Sets up an ability to add aria-label to core/list block
Adds custom style for the post title block to be styled in accordance with styling needs for digital.gov.bc.ca
Custom WordPress theme - the theme performs these functions:
./functions.php:
Includes CSS file to display blocks correctly inside the editor. Similar CSS is mirrored on the front end as well.
Removes support for default WordPress patterns - to restrict degrees of freedom available to content editors in an effort to keep look-and-feel consistent with design guidelines
./style.css - CSS to display blocks in a way that’s consistent with digital.gov.bc.ca in the block editor
The code for both custom WordPress theme and plugin are hosted on GitHub here: https://github.com/bcgov/wordpress-digimod
WordPress Deployment
WordPress deployment project is a fork of https://github.com/bcgov/wordpress and is available on GitHub here: https://github.com/bcgov/wordpress-deploy-digimod
To deploy WordPress to OpenShift follow these steps:
Follow instructions in
openshift/templates/images/readme.md
to create base imagesTo build images run builds manually through OpenShift Web UI or use GitHub actions (untested)
Rename image stream tags to
test
orprod
, whichever is appropriate:oc -n c0cce6-tools tag wordpress-mariadb-run:dev wordpress-mariadb-run:test oc -n c0cce6-tools tag wordpress-nginx-run:dev wordpress-nginx-run:test oc -n c0cce6-tools tag wordpress-wordpress-run:dev wordpress-wordpress-run:test oc -n c0cce6-tools tag wordpress-sidecar-run:dev wordpress-sidecar-run:test
Run
openshift/templates/site-builder.sh
- this will setup config, mariaDB, nginx.
Next.JS
Next.JS is responsible for fetching the content from WordPress through the API, parsing the WordPress HTML into React components and serving resulting HTML to the client. On the client, React.js is responsible for re-hydrating any React components for interactive functionality. If the user disables JavaScript, the site is expected to run a standard website instead of a Single Page Application (SPA). Interactive elements, such as accordions should either work through CSS toggles or be accessible without interactive (for example leaving accordions expanded, or rendered differently).
Next.JS application is hosted on GitHub here: https://github.com/bcgov/nextjs-digimod
Next.JS Deployment
To deploy Next.JS application to OpenShift run following commands:
oc apply -f image-stream.yaml
oc apply -f .\build-config.yaml
Start the build manually from the build config through the OpenShift web interface.
Navigate to the Developer Topology view and select the Add Page link. From the Add page, select Container images. From the Deploy image page that pops up, select Image stream tag from internal registry, and then ubi8-nextjs for the Image Stream and latest for the Tag. Scroll down and set the Target port to match the value in our Dockerfile, which is 3000. Accept the rest of the default values and select Create.