lxl.harvest

Harvests data from given endpoints and saves them to a local folder

Usage no npm install needed!

<script type="module">
  import lxlHarvest from 'https://cdn.skypack.dev/lxl.harvest';
</script>

README

LxLabs Harvest Function

WordPress REST API calls take time, hammer users' bandwidth, occasionally fail, and don't really work offline.

The solution? We do all of the heavy lifting instead!

We can move the API request to build time instead of render time - using this handy harvest function!

This README is for version 1.1.2 and it would be appreciated if it was kept up-to-date if there are any changes made to the processes detailed here.

Getting started

Step 1

Install the package in your project using

npm install lxl.harvest

Step 2

Create a local task file

// harvest.js

const Harvest = require('lxl.harvest');

const options = {
  API: 'http://localhost/wp-json/wp/v2',
  ENDPOINTS: ['posts', 'pages'],
  FOLDER: 'src/_data',
  PERPAGE: 100,
}

const myApp = new Harvest(options);

myApp.init();

options

Key Value
API The endpoint of the CMS
ENDPOINTS An array of endpoints
FOLDER The destination folder for the returned data
PERPAGE The maximum number of posts per page

Step 3

Either run the task directly with node harvest.js or add the task to your build process in package.json

For example;

{ 
  "scripts": {
    "harvest": "node harvest.js",
  }
}
npm run harvest

Support 💪

Gotchas! 🤔

Housekeeping 🛋