mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-07-04 11:36:37 -04:00
test cache plugin for Netlify
This commit is contained in:
27
plugins/netlify-plugin-cache/index.js
Normal file
27
plugins/netlify-plugin-cache/index.js
Normal file
@ -0,0 +1,27 @@
|
||||
// Based on https://github.com/cdeleeuwe/netlify-plugin-hugo-cache-resources/blob/master/index.js
|
||||
|
||||
module.exports = {
|
||||
async onPreBuild({ utils, inputs }) {
|
||||
const paths = JSON.parse(inputs.paths);
|
||||
const success = await utils.cache.restore(paths);
|
||||
|
||||
if (success) {
|
||||
const cachedFiles = await utils.cache.list(paths);
|
||||
console.log(`Restored cache of '${paths}', totaling ${cachedFiles.length} files.`);
|
||||
} else {
|
||||
console.log(`A cache of '${paths}' doesn't exist (yet).`);
|
||||
}
|
||||
},
|
||||
|
||||
async onPostBuild({ utils, inputs }) {
|
||||
const paths = JSON.parse(inputs.paths);
|
||||
const success = await utils.cache.save(paths);
|
||||
|
||||
if (success) {
|
||||
const cachedFiles = await utils.cache.list(paths);
|
||||
console.log(`Successfully cached '${paths}', totaling ${cachedFiles.length} files.`);
|
||||
} else {
|
||||
console.log(`Couldn't cache '${paths}'.`);
|
||||
}
|
||||
}
|
||||
};
|
4
plugins/netlify-plugin-cache/manifest.yml
Normal file
4
plugins/netlify-plugin-cache/manifest.yml
Normal file
@ -0,0 +1,4 @@
|
||||
name: netlify-plugin-cache
|
||||
inputs:
|
||||
- name: paths
|
||||
description: Array of directories to cache between builds.
|
Reference in New Issue
Block a user