mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-04-28 08:30:28 -04:00
28 lines
893 B
JavaScript
28 lines
893 B
JavaScript
// 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}'.`);
|
|
}
|
|
}
|
|
};
|