Skip to content

Commit 5b2cfc8

Browse files
committed
cleanup config
1 parent 87c6f2a commit 5b2cfc8

File tree

5 files changed

+122
-40
lines changed

5 files changed

+122
-40
lines changed

README.md

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,82 @@
1-
Netlify Build plugin 11ty - A build plugin to integrate Eleventy seamlessly with Netlify.
1+
Netlify Build plugin 11ty - A build plugin to integrate Eleventy seamlessly with
2+
Netlify.
23

34
# Install
45

5-
Please install this plugin from the Netlify app.
6+
Install plugin via npm as dependency
67

7-
# Configuration
8+
**Note**: Till https://github.com/11ty/eleventy-img/pull/116 is merged,
9+
[this fork](https://github.com/zeroby0/eleventy-img/tree/cache) has to be used instead of `@11ty/eleventy-img`
810

9-
The following `inputs` options are available.
11+
```
12+
npm install zeroby0/netlify-plugin-11ty
13+
npm uninstall @11ty/eleventy-img
14+
npm install zeroby0/eleventy-img#cache
15+
```
16+
17+
And add to your `netlify.toml` file
18+
19+
```toml
20+
[[plugins]]
21+
package = "netlify-plugin-11ty"
22+
```
23+
24+
# configuration
25+
26+
Optionally, you can configure the plugin to match you project's needs.
27+
28+
**Example**:
29+
30+
```toml
31+
[[plugins]]
32+
package = "netlify-plugin-11ty"
33+
[plugins.inputs]
34+
cache_img = './img'
35+
cache_img_httpHeader = true
36+
37+
cache_assets = '../.cache'
38+
cache_other = []
39+
```
40+
41+
The following `inputs` options are available:
42+
43+
#### cache_img
44+
45+
Type: `string` or `Array of strings` Default: `'./img'` (relative to the publish
46+
directory)
47+
48+
The folder(s) in which files generated by `@11ty/eleventy-img` are stored,
49+
relative to publish directory. Can be a string or an array of strings.
50+
51+
If set to `false`, files generated by `@11ty/eleventy-img` are not saved in
52+
Netlify cache.
53+
54+
#### cache_img_httpHeader
55+
56+
Type: boolean Default: `true`
57+
58+
If set to `true`, a files generated by `@11ty/eleventy-img` will be served with
59+
http header `cache-control: public, max-age=31536000, immutable`.
60+
61+
This should be safe to do as the file names have a hash calculated using file
62+
content and Sharp Options.
63+
64+
#### cache_assets
65+
66+
Type: `string` or `Array of strings` Default: `'../.cache'` (relative to the
67+
publish directory)
68+
69+
The folder(s) in which remote assets fetched by `@11ty/eleventy-cache-assets`
70+
are cached, relative to publish directory. Can be a string or an array of
71+
strings.
72+
73+
If set to `false`, assets fetched by `@11ty/eleventy-cache-assets` are not saved
74+
in Netlify cache.
75+
76+
#### cache_other
77+
78+
Type: `string` or `Array of strings` Default: `[]` (relative to the publish
79+
directory)
80+
81+
Any other folder(s) you'd like to cache across Netlify builds. If these folders
82+
exist before restoring Nelify cache, they will be replaced with cached folders.

manifest.yml

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
name: 'netlify-plugin-11ty'
22
inputs:
3-
- name: img_cache_local
4-
description: 'Cache images generated by 11ty Image plugin'
5-
default: true
6-
7-
- name: img_cache_local_dir
8-
description: '11ty image plugin output directory'
9-
default: '/img'
10-
11-
- name: img_cache_remote
12-
default: '../cache'
3+
- name: cache_img
4+
description: '11ty Image plugin output directory'
5+
default: './img'
136

14-
- name: img_cache_remote_dir
15-
default: '../cache'
16-
17-
- name: img_cache_httpHeader
7+
- name: cache_img_httpHeader
8+
description: 'Add immutable cache http headers'
189
default: true
1910

20-
- name: other_cache_dir
11+
- name: cache_assets
12+
description: '11ty Assets plugin cache directory'
13+
default: '../.cache'
14+
15+
- name: cache_other
16+
description: 'Any other directories you want to cache'
2117
default: []

netlify.toml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,11 @@
66
[[plugins]]
77
package = "."
88
[plugins.inputs]
9-
img_cache_local = true
10-
img_cache_local_dir = '/img'
9+
cache_img = false
10+
cache_img_httpHeader = true
1111

12-
img_cache_remote = true
13-
img_cache_remote_dir = '../.cache'
14-
15-
img_cache_httpHeader = true
16-
17-
other_cache_dir = []
12+
cache_assets = '../.cache'
13+
cache_other = []
1814

1915
[build]
2016
base = "./"

package.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"name": "netlify-plugin-11ty",
33
"version": "0.0.1",
44
"description": "Netlify Build plugin - A build plugin to integrate Eleventy seamlessly with Netlify",
5+
"publishConfig": {
6+
"access": "public"
7+
},
58
"main": "src/index.js",
69
"files": [
710
"src/**/*.js",
@@ -15,9 +18,17 @@
1518
"netlify-plugin",
1619
"netlify"
1720
],
18-
"author": "Aravind Reddy Voggu <aravind.reddy@iiitb.org>",
21+
"author": {
22+
"name": "Aravind Reddy Voggu",
23+
"email": "aravind.reddy@iiitb.org",
24+
"url": "https://www.avoggu.com"
25+
},
1926
"license": "MIT",
20-
"repository": "//github.com/zeroby0/netlify-plugin-11ty",
27+
"repository": "https://github.com/zeroby0/netlify-plugin-11ty",
28+
"bugs": {
29+
"url": "https://github.com/zeroby0/netlify-plugin-11ty/issues"
30+
},
31+
"homepage": "https://github.com/zeroby0/netlify-plugin-11ty#readme",
2132
"directories": {
2233
"lib": "src",
2334
"test": "test"

src/index.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const fs = require('fs')
44
const getCacheDirs__ = (base, input) => {
55
let cacheDirs = []
66

7+
if (!input) return []
8+
79
if (typeof input === 'string') {
810
cacheDirs.push(path.normalize(base + '/' + input))
911
} else if (Array.isArray(input)) {
@@ -19,21 +21,21 @@ const getCacheDirs__ = (base, input) => {
1921

2022
const getCacheDirs = (base, inputs) => {
2123
return [
22-
...getCacheDirs__(base, inputs.img_cache_local_dir),
23-
...getCacheDirs__(base, inputs.img_cache_remote_dir),
24-
...getCacheDirs__(base, inputs.other_cache_dir),
24+
...getCacheDirs__(base, inputs.cache_img),
25+
...getCacheDirs__(base, inputs.cache_assets),
26+
...getCacheDirs__(base, inputs.cache_other),
2527
]
2628
}
2729

2830
const getHttpHeaders = (inputs) => {
2931
let httpHeader = ''
3032

31-
getCacheDirs__('.', inputs.img_cache_local_dir).map((x) => {
33+
getCacheDirs__('.', inputs.cache_img).map((x) => {
3234
httpHeader += `
3335
${x}/*
34-
cache-control: public
35-
cache-control: max-age=31536000
36-
cache-control: immutable
36+
cache-control: public
37+
cache-control: max-age=31536000
38+
cache-control: immutable
3739
3840
`
3941
})
@@ -56,6 +58,12 @@ module.exports = {
5658
`Warning: directory ${x} already exists before restoring caches. It will be replaced if it exists in the cache.`,
5759
)
5860
}
61+
62+
if (path.normalize(x) === path.normalize(constants.PUBLISH_DIR)) {
63+
console.log(
64+
`11ty sites must publish the dist directory, but your site’s publish directory is set to : “${constants.PUBLISH_DIR}”.`,
65+
)
66+
}
5967
})
6068

6169
if (await utils.cache.restore(cacheDirs)) {
@@ -77,7 +85,7 @@ module.exports = {
7785
console.log('- ' + x)
7886
})
7987

80-
if (inputs.img_cache_httpHeader) {
88+
if (inputs.cache_img_httpHeader) {
8189
fs.appendFile(
8290
`${constants.PUBLISH_DIR}/_headers`,
8391
getHttpHeaders(inputs),
@@ -88,9 +96,7 @@ module.exports = {
8896
)
8997
}
9098
} else {
91-
console.log(
92-
`Warning: Unable to save 11ty cache. Build not found or is empty. Is you publish directory set correctly? “${constants.PUBLISH_DIR}”`,
93-
)
99+
console.log('Did not save any folders to cache.')
94100
}
95101
},
96102
}

0 commit comments

Comments
 (0)