1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2025-10-28 16:55:50 -04:00

test cache plugin for Netlify

This commit is contained in:
2020-06-05 17:29:22 -04:00
parent 85fe0084b8
commit eafbf87f49
6 changed files with 47 additions and 1 deletions

1
.eslintignore Normal file
View File

@@ -0,0 +1 @@
plugins/

View File

@@ -9,6 +9,9 @@ builds/
resources/
_vendor/
# Netlify plugins
plugins/
# dotfiles/config
.*
postcss.config.js

View File

@@ -37,6 +37,17 @@
publish = "public"
autoLaunch = false
# Cache resoures between builds, see plugins/netlify-plugin-cache/index.js
[[plugins]]
package = "/plugins/netlify-plugin-cache"
[plugins.inputs]
# TODO: make this better.
paths = "[\"resources\", \"_vendor\"]"
[[plugins]]
package = "netlify-plugin-debug-cache"
[[plugins]]
package = "@netlify/plugin-local-install-core"
# The most important headers and redirects are specified in the _headers and
# _redirects files generated by Hugo. These are additional custom rules.

View File

@@ -14,7 +14,7 @@
"url": "git+https://github.com/jakejarvis/jarv.is.git"
},
"scripts": {
"clean": "rimraf public/ resources/ builds/ && hugo mod clean",
"clean": "rimraf public/ builds/",
"build": "run-s clean hugo minify",
"build:preview": "run-s clean hugo:dev",
"hugo": "hugo --gc --cleanDestinationDir --verbose",

View 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}'.`);
}
}
};

View File

@@ -0,0 +1,4 @@
name: netlify-plugin-cache
inputs:
- name: paths
description: Array of directories to cache between builds.