Skip to content

Using the WordPress API, deploys posts to a target GitHub location; specifically the covid19.ca.gov website.

Notifications You must be signed in to change notification settings

carterm/wordpress-integration-api

 
 

Repository files navigation

Wordpress content integration service for Covid19.ca.gov

Using the WordPress API, deploys posts to a target GitHub location and facilitates translations; specifically for the covid19.ca.gov website.

See below for an outline of the Translation Pipeline.

Features

  • Pushes post content updates to a GitHub repository (Add/Update/Delete)
  • Submits posts with the translate tag to the AvantPage endpoint for human translation
  • Temporary execution log
  • Slack error reporting

NOT included

  • WordPress image support
  • Support for pages or any other non-post content

Usage

The service can be run directly by pressing a form button on its running function site, or as the target of a POST request.

WordPress post tags used

Tag Description
do-not-deploy Ignores the post when processing
staging-only Ignores the post when the target is the master branch only
translate Changes to the post are submitted to the remote translation service
translate-priority Combined with translate, translation submitions will be marked priority:true
table-data Alternatively creates JSON file output using any tables defined in the post
fragment Renders the HTML post output without any YAML front matter data
do-not-crawl Returns addtositemap: false in the front matter data
lang-XX Deprecated. Was used to identify a page as a specific language. No effect

Front matter output mapping

Attribute Description
layout Always "page.njk"
title From API - title.rendered
meta From API - excerpt.rendered (<p> tags and /n removed)
author Always "State of California"
publishdate From API - modified_gmt
addtositemap "true" unless do-not-crawl tag used
tags Array mapped to strings from API - tags

WordPress API endpoints required

Tag Purpose
/wp-json/wp/v2/categories Unknown. May have been used in the past instead of tags. - Might not be needed anymore
/wp-json/wp/v2/tags Used to match post tags to their ids
/wp-json/wp/v2/posts Used to retrieve post data

Local development

The project expects the Azure Functions SDK to be installed in order to run locally.

TODO: It would be great to have the project configured to run without the SDK and just use the VSCode debugger.

Target GitHub location

Running production service

Source GitHub repo

Translation pipeline for covid19.ca.gov

The California COVID-19 website supports multiple translated languages. To allow for this, a translation pipeline will be created that ensures continuous human translation as English language updates are made.

Actors

  • ODI - Office of Digital Innovation
  • AT - Avantpage Translations

Assumptions

  • Notifications between services will not be authenticating.
  • Content will be downloaded (GET) by services, rather than pushed to them.
  • Content delivered to ODI will not be reviewed by ODI; it will be deployed to ODI production/staging environments immediately.

Process

  1. ODI content writers will author English versions in WordPress.
  2. WordPress will send a POST to the wordpress-integration-api service when a post content change occures. The content of the POST is ignored.
  3. The wordpress-integration-api service will scan WordPress for post updates and sync content updates to GitHub.
  4. The wordpress-integration-api will send a post payload to AT for any post updates that are tagged as translate. See POST payload from ODI to AT for details.
  5. AT will GET full page content directly from GitHub.
  6. AT will perform translation work.
  7. AT will create a GitHub pull request containing updated translation content.
    • The pull request will be labeled Translated Content
  8. ODI will approve appropriately tagged pull requests via CovidTranslationPrApproval, but only when they:
    • Have passed all their check runs
    • Only contain content within the pages/translated-posts folder
    • Do not contain invalid characters
  9. GitHub will build and publish with updated translations.

POST payload from ODI to AT

When wordpress-integration-api notifies AT that changes have occurred, the following JSON payload should be used.

Property Description
id WordPress id of post
slug WordPres slug of post
modified GMT date/time of modification
priority Optional. true for a priority translation
download_path GitHub path to download HTML or JSON content. Example - /master/pages/wordpress-posts/contracts.html

Sample JSON payload

{
    "posts":
	[
		{
    		"id": 36,
    		"slug": "education",
    		"modified": "2020-04-27T23:14:07",
    		"download_path": "/master/pages/wordpress-posts/education.html",
		    "priority": true //Optional to indicate a priority translation
		}
	]
	,"test": 1  ///Optional to indicate a test request
}

HTML content requirements

Content aquired for translations could be in JSON or HTML format.

When the content is in HTML format, it is possible that the file could have 11ty front matter data. AT is expected to maintain the field names for front matter data when performing translations, as well as class and variable names for HTML content.

Example English content with front matter

---
layout: "page.njk"
title: "Data and tools"
meta: "California has collected a wide range of data to inform its response to COVID-19."
author: "State of California"
publishdate: "2022-03-07T18:15:10Z"
tags: ["translate"]
addtositemap: true
---
<p class="emphasized">California has collected a wide range of data to inform its response to COVID-19, and developed tools to help process and analyze that data. These are made available to everyone for transparency.</p>

<p class="h3">On this page:</p>

Example translated to Simplified Chinese

---
layout: "page.njk"
title: "数据及工具"
meta: "加州已经收集了大量数据,为应对COVID-19提供了信息。"
author: "State of California"
publishdate: "2022-03-07T18:15:10Z"
tags: ["translate"]
addtositemap: true
---
<p class="emphasized">加州已经收集了大量数据,以发布应对COVID-19的信息,并开发了工具以协助处理并分析这些数据。为保证公开透明,所有人都可查看这些数据。</p>

<p class="h3">此页面包含的内容:</p>

About

Using the WordPress API, deploys posts to a target GitHub location; specifically the covid19.ca.gov website.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 97.7%
  • HTML 2.3%