Skip to content

Commit

Permalink
Merge pull request #6 from cdeleeuwe/srcdir_option
Browse files Browse the repository at this point in the history
Add srcdir option
  • Loading branch information
cdeleeuwe committed Dec 19, 2020
2 parents bbfe8d7 + b0c908e commit c6a4c34
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 8 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -20,6 +20,8 @@ To install, add the following lines to your `netlify.toml` file:
[plugins.inputs]
# If it should show more verbose logs (optional, default = true)
debug = true
# Relative path to source directory in case you use Hugo's "--s" option
srcdir = "path/to/website"
```

Note: The `[[plugins]]` line is required for each plugin, even if you have other plugins in your `netlify.toml` file already.
2 changes: 1 addition & 1 deletion example/config.yml
Expand Up @@ -6,4 +6,4 @@ imaging:
resampleFilter: Lanczos

params:
amount: 500
amount: 10
1 change: 1 addition & 0 deletions example/netlify.toml
@@ -1,6 +1,7 @@
[build]
publish = "public"
command = "hugo --gc --minify"
ignore = "(exit 1)"

[build.environment]
HUGO_VERSION = "0.74.3"
Expand Down
11 changes: 7 additions & 4 deletions index.js
@@ -1,5 +1,7 @@
const getResourcesDir = () => {
return 'resources';
const { join } = require("path");

const getResourcesDir = ({ inputs }) => {
return join(inputs.srcdir, 'resources');
}

const printList = (items) => {
Expand All @@ -12,8 +14,9 @@ const printList = (items) => {
module.exports = {

async onPreBuild({ utils, inputs }) {
const path = getResourcesDir();
const path = getResourcesDir({ inputs });
const success = await utils.cache.restore(path);
console.log(`Checking if resources exist at "${path}"`);

if (success) {
const cachedFiles = await utils.cache.list(path);
Expand All @@ -25,7 +28,7 @@ module.exports = {
},

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

if (success) {
Expand Down
5 changes: 4 additions & 1 deletion manifest.yml
Expand Up @@ -2,4 +2,7 @@ name: netlify-plugin-hugo-cache
inputs:
- name: debug
description: Show more verbose logs
default: true
default: true
- name: srcdir
description: Relative path to source directory in case you use Hugo's "--s" option
default: ""
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "netlify-plugin-hugo-cache-resources",
"version": "0.1.6",
"version": "0.2.0",
"description": "Persist Hugo resources folder between Netlify builds for huge build speed improvements!",
"main": "index.js",
"repository": "https://github.com/cdeleeuwe/netlify-plugin-hugo-cache-resources.git",
Expand Down

0 comments on commit c6a4c34

Please sign in to comment.