Welcome to mirror list, hosted at ThFree Co, Russian Federation.

index.js « netlify-plugin-hugo-cache-resources « plugins « exampleSite - github.com/CaiJimmy/hugo-theme-stack.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fd8ffb6506b750401589a6186afbe48dada8a222 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const getResourcesDir = () => {
  return 'exampleSite/resources';
}

const printList = (items) => {
  console.log('---');
  items.forEach((item, index) => {
    console.log(`${index + 1}. ${item}`);
  });
}

module.exports = {

  async onPreBuild({ utils, inputs }) {
    const path = getResourcesDir();
    const success = await utils.cache.restore(path);

    if (success) {
      const cachedFiles = await utils.cache.list(path);
      console.log(`Restored cached resources folder. Total files: ${cachedFiles.length}`);
      if (inputs.debug) printList(cachedFiles);
    } else {
      console.log(`No cache found for resources folder`);
    }
  },

  async onPostBuild({ utils, inputs }) {
    const path = getResourcesDir();
    const success = await utils.cache.save(path);

    if (success) {
      const cachedFiles = await utils.cache.list(path);
      console.log(`Saved resources folder to cache. Total files: ${cachedFiles.length}`);
      if (inputs.debug) printList(cachedFiles);
    } else {
      console.log(`No resources folder cached`);
    }
  }
};