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:
1
.eslintignore
Normal file
1
.eslintignore
Normal file
@@ -0,0 +1 @@
|
||||
plugins/
|
||||
@@ -9,6 +9,9 @@ builds/
|
||||
resources/
|
||||
_vendor/
|
||||
|
||||
# Netlify plugins
|
||||
plugins/
|
||||
|
||||
# dotfiles/config
|
||||
.*
|
||||
postcss.config.js
|
||||
|
||||
11
netlify.toml
11
netlify.toml
@@ -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.
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
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