1.1.2 • Published 5 years ago

lxl.harvest v1.1.2

Weekly downloads
-
License
ISC
Repository
-
Last release
5 years ago

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

KeyValue
APIThe endpoint of the CMS
ENDPOINTSAn array of endpoints
FOLDERThe destination folder for the returned data
PERPAGEThe 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 🛋

1.1.2

5 years ago

1.1.1

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago