This repository contains an Eleventy boilerplate, as well as an AWS Lambda-compatible Netlify Function acting as a webhook target, for fetching data from a WordPress REST API and automatically commit and push to the Github repository stored in the package.json file.
After updating the repository, preconfigured Github Actions rebuild and re-deploy the newly built site contents back to Netlify.
This way, access to the WordPress REST API and/or SQL database is not crucially needed for intermediate builds, as their latest content versions are always contained within this repository and even survive data loss within WordPress.
- Node.js v16+
- Yarn or similar (optional)
- WordPress - 2 possibilities:
- locally installed via XAMPP, etc...
- running in a Docker container (see running via
docker-compose
)
-
Install dependencies
yarn # or npm install
-
Populate Eleventy's data sources locally. (Wordpress instance needs to be reachable)
REST_API=<WordPress REST API endpoint> ts-node scripts/fetch.ts
-
Run development preview
yarn dev # or npm run dev
- Account at Netlify
- Enabled Github Actions setup, incl. necessary environment variables (see .env.sample and deploy-to-netlify.yml - Deploy to Netlify step), OR
- directly build at Netlify (untested, set environment variables in .env.sample there, disable Github Actions)
- WordPress deployed somewhere with accessible REST API
To trigger a new deployment, the /wp/hook
endpoint needs to be called using a POST
request (the request body is ignored by default).
Any WordPress plugin, which is capable of sending a POST request (preferably with Basic authentication) whenever contents have changed should do. Something like this one: WP Webhooks.
Or, if periodical updates are preferred over updates based on content changes, something like Netlify's Scheduled Functions might do the trick.
Licensed under the MIT license.
Copyright ©️ 2022 Sascha Zarhuber