eleventy-plugin-vento 3.0.0 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/package.json +9 -9
- package/src/engine.js +58 -61
- package/src/index.js +20 -12
- package/src/modules/create-vento-tag.js +2 -2
- package/src/modules/utils.js +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# eleventy-plugin-vento
|
|
2
2
|
|
|
3
|
+
## 3.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e46ce6e: Integrate eleventy and vento caching.
|
|
8
|
+
|
|
9
|
+
There have been a few issues around managing Vento's cache that have yielded uninteded results when compiling templates (ie #10, #34). This update integrates Vento's cache with Eleventy's custom extension API.
|
|
10
|
+
|
|
11
|
+
This means that whether running Eleventy in `--serve` mode or compiling dynamic permalinks, stale cache data actually gets removed so Vento can compile the template from source again.
|
|
12
|
+
|
|
13
|
+
Raise any issues if caching behavior continues to be an issue!
|
|
14
|
+
|
|
15
|
+
## 3.0.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 9f5a90f: Various Refactors - These changes shouldn't have any observable effect on your templates or usage.
|
|
20
|
+
|
|
21
|
+
- Replaced `class` based approach for a closure implementation instead. Since there was only 1 Vento `env` object ever instanced in this plugin, steering away from using `class` removes some complexity and overhead.
|
|
22
|
+
|
|
23
|
+
- `DATA_KEYS` (used internally) moved into utils file alongside other utilities (like compatibility checks) and renamed to `CONTEXT_DATA_KEYS`.
|
|
24
|
+
|
|
25
|
+
- Moved internal Vento/11ty data from env.\_11ty => env.utils.\_11ty. Previous versions mutated the Vento `env` object by adding an `_11ty` key with everything that needed accessing from within a template compile (shortcodes, filters, etc.). This was moved this back to `env.utils._11ty` since it's probably a more appropriate place to store these functions.
|
|
26
|
+
|
|
3
27
|
## 3.0.0
|
|
4
28
|
|
|
5
29
|
### Major Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eleventy-plugin-vento",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"description": "Adds support for the Vento templating language to Eleventy.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -35,15 +35,15 @@
|
|
|
35
35
|
"ventojs": "1.12.10"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@11ty/eleventy": "3.0.0
|
|
39
|
-
"@changesets/cli": "2.27.
|
|
40
|
-
"eslint": "9.
|
|
38
|
+
"@11ty/eleventy": "3.0.0",
|
|
39
|
+
"@changesets/cli": "2.27.9",
|
|
40
|
+
"eslint": "9.12.0",
|
|
41
41
|
"eslint-config-flat-gitignore": "0.3.0",
|
|
42
42
|
"eslint-config-prettier": "9.1.0",
|
|
43
|
-
"eslint-plugin-unicorn": "
|
|
44
|
-
"globals": "15.
|
|
45
|
-
"vitest": "2.1.
|
|
46
|
-
"zx": "8.1.
|
|
43
|
+
"eslint-plugin-unicorn": "56.0.0",
|
|
44
|
+
"globals": "15.11.0",
|
|
45
|
+
"vitest": "2.1.2",
|
|
46
|
+
"zx": "8.1.9"
|
|
47
47
|
},
|
|
48
48
|
"prettier": {
|
|
49
49
|
"bracketSameLine": true,
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"lint": "eslint '**/*.js'",
|
|
57
57
|
"ci:version": "changeset version && pnpm install --no-frozen-lockfile",
|
|
58
58
|
"ci:publish": "changeset publish",
|
|
59
|
-
"ci:generate-changesets": "node ./scripts/generate-changesets.
|
|
59
|
+
"ci:generate-changesets": "node ./scripts/generate-changesets.js",
|
|
60
60
|
"format": "pnpm dlx prettier --config ./package.json --write ."
|
|
61
61
|
}
|
|
62
62
|
}
|
package/src/engine.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @file
|
|
2
|
+
* @file Function that handles creating the Vento environment. Exposes
|
|
3
|
+
* a simple API for Eleventy to interface with.
|
|
3
4
|
*
|
|
4
5
|
* @typedef {{eleventy?: Record<string, unknown>, page?: Record<string, unknown>}} EleventyContext
|
|
5
6
|
* @typedef {Context & Record<string, unknown>} EleventyData
|
|
6
7
|
* @typedef {(...args: unknown[]) => unknown} EleventyFunction
|
|
7
8
|
* @typedef {import('ventojs/src/environment.js').Environment} VentoEnvironment
|
|
8
|
-
* @typedef {VentoEnvironment & {
|
|
9
|
+
* @typedef {VentoEnvironment & {
|
|
10
|
+
* utils: { _11ty: { ctx: Context, tags: Record<string, EleventyFunction> } }
|
|
11
|
+
* }} EleventyVentoEnvironment
|
|
9
12
|
*/
|
|
10
13
|
|
|
11
14
|
// External library
|
|
@@ -13,73 +16,67 @@ import ventojs from 'ventojs';
|
|
|
13
16
|
|
|
14
17
|
// Internal modules
|
|
15
18
|
import { createVentoTag } from './modules/create-vento-tag.js';
|
|
19
|
+
import { CONTEXT_DATA_KEYS } from './modules/utils.js';
|
|
16
20
|
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
/** @param {import('ventojs').Options} options */
|
|
22
|
+
export function createVentoEngine(options) {
|
|
23
|
+
/** @type {EleventyVentoEnvironment} */
|
|
24
|
+
const env = ventojs(options);
|
|
25
|
+
env.utils._11ty = { ctx: {}, functions: {} };
|
|
19
26
|
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
return {
|
|
28
|
+
/** @param {string} path */
|
|
29
|
+
getCachedSource(path) {
|
|
30
|
+
return env.cache.get(path)?.source;
|
|
31
|
+
},
|
|
22
32
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this.#env._11ty = { ctx: {}, functions: {} };
|
|
28
|
-
}
|
|
33
|
+
/** @param {string} path */
|
|
34
|
+
emptyCache(path) {
|
|
35
|
+
return path ? env.cache.delete(path) : env.cache.clear();
|
|
36
|
+
},
|
|
29
37
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
38
|
+
/** @param {import('ventojs/src/environment.js').Plugin[]} plugins */
|
|
39
|
+
loadPlugins(plugins) {
|
|
40
|
+
for (const plugin of plugins) {
|
|
41
|
+
env.use(plugin);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
34
44
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
45
|
+
/** @param {PageData} newContext */
|
|
46
|
+
loadContext(newContext) {
|
|
47
|
+
// Loop through allowed keys and load those into the context
|
|
48
|
+
for (const K of CONTEXT_DATA_KEYS) {
|
|
49
|
+
env.utils._11ty.ctx[K] = newContext[K];
|
|
50
|
+
}
|
|
51
|
+
},
|
|
41
52
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
}
|
|
53
|
+
/** @param {Record<string, EleventyFunction>} filters */
|
|
54
|
+
loadFilters(filters) {
|
|
55
|
+
for (const [name, fn] of Object.entries(filters)) {
|
|
56
|
+
env.filters[name] = (...args) => fn.apply(env.utils._11ty.ctx, args);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
49
59
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
60
|
+
/**
|
|
61
|
+
* @param {Record<string, EleventyFunction>} shortcodes
|
|
62
|
+
* @param {boolean} paired
|
|
63
|
+
*/
|
|
64
|
+
loadShortcodes(shortcodes, paired = false) {
|
|
65
|
+
for (const [name, fn] of Object.entries(shortcodes)) {
|
|
66
|
+
env.utils._11ty.functions[name] = fn;
|
|
67
|
+
env.tags.push(createVentoTag(name, paired));
|
|
68
|
+
}
|
|
69
|
+
},
|
|
56
70
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
loadShortcodes(shortcodes, paired = false) {
|
|
62
|
-
for (const [name, fn] of Object.entries(shortcodes)) {
|
|
63
|
-
this.#env._11ty.functions[name] = fn;
|
|
64
|
-
this.#env.tags.push(createVentoTag(name, paired));
|
|
65
|
-
}
|
|
66
|
-
}
|
|
71
|
+
/** @param {{data: PageData, source: string, path: string}} input */
|
|
72
|
+
async process(input) {
|
|
73
|
+
// Reload context
|
|
74
|
+
this.loadContext(input.data);
|
|
67
75
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
* @param {string} content
|
|
71
|
-
* @param {string} path
|
|
72
|
-
*/
|
|
73
|
-
async process(data, content, path) {
|
|
74
|
-
// Reload context
|
|
75
|
-
this.loadContext(data);
|
|
76
|
+
// Process the templates
|
|
77
|
+
const result = await env.runString(input.source, input.data, input.path);
|
|
76
78
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
// Clear the cache for this path if the input doesn't match
|
|
81
|
-
if (data.page?.rawInput !== content) this.#env.cache.clear(path);
|
|
82
|
-
|
|
83
|
-
return result.content;
|
|
84
|
-
}
|
|
79
|
+
return result.content;
|
|
80
|
+
},
|
|
81
|
+
};
|
|
85
82
|
}
|
package/src/index.js
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
import autotrimPlugin, { defaultTags as autotrimDefaultTags } from 'ventojs/plugins/auto_trim.js';
|
|
25
25
|
|
|
26
26
|
// Local modules
|
|
27
|
-
import {
|
|
27
|
+
import { createVentoEngine } from './engine.js';
|
|
28
28
|
import { ignoreTagPlugin } from './modules/ignore-tag.js';
|
|
29
29
|
import { runCompatibilityCheck } from './modules/utils.js';
|
|
30
30
|
|
|
@@ -87,23 +87,20 @@ export function VentoPlugin(eleventyConfig, userOptions) {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
// Create the vento engine instance
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
// Ensure cache is empty
|
|
93
|
-
vento.emptyCache();
|
|
90
|
+
const engine = createVentoEngine(options.ventoOptions);
|
|
94
91
|
|
|
95
92
|
// Load plugins
|
|
96
|
-
|
|
93
|
+
engine.loadPlugins(options.plugins);
|
|
97
94
|
|
|
98
95
|
// Add filters, single and paired shortcodes if enabled
|
|
99
96
|
if (options.filters) {
|
|
100
|
-
|
|
97
|
+
engine.loadFilters(filters);
|
|
101
98
|
}
|
|
102
99
|
if (options.shortcodes) {
|
|
103
|
-
|
|
100
|
+
engine.loadShortcodes(shortcodes, false);
|
|
104
101
|
}
|
|
105
102
|
if (options.pairedShortcodes) {
|
|
106
|
-
|
|
103
|
+
engine.loadShortcodes(pairedShortcodes, true);
|
|
107
104
|
}
|
|
108
105
|
|
|
109
106
|
// Add vto as a template format
|
|
@@ -116,14 +113,25 @@ export function VentoPlugin(eleventyConfig, userOptions) {
|
|
|
116
113
|
|
|
117
114
|
// Main compile function
|
|
118
115
|
async compile(inputContent, inputPath) {
|
|
119
|
-
return async (data) =>
|
|
116
|
+
return async (data) => await engine.process({ data, source: inputContent, path: inputPath });
|
|
120
117
|
},
|
|
121
118
|
|
|
122
119
|
// Custom permalink compilation
|
|
123
120
|
compileOptions: {
|
|
121
|
+
cache: true,
|
|
122
|
+
getCacheKey(inputContent, inputPath) {
|
|
123
|
+
if (engine.getCachedSource(inputPath) !== inputContent) {
|
|
124
|
+
engine.emptyCache(inputPath);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return engine.getCachedSource(inputPath);
|
|
128
|
+
},
|
|
124
129
|
permalink(linkContents) {
|
|
125
|
-
if (typeof linkContents !== 'string')
|
|
126
|
-
|
|
130
|
+
if (typeof linkContents !== 'string') {
|
|
131
|
+
return linkContents;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return async (data) => engine.process({ data, source: linkContents });
|
|
127
135
|
},
|
|
128
136
|
},
|
|
129
137
|
});
|
|
@@ -11,8 +11,8 @@ export function createVentoTag(name, paired) {
|
|
|
11
11
|
if (!code.startsWith(name)) return;
|
|
12
12
|
|
|
13
13
|
// Declare helper object path strings
|
|
14
|
-
const fn = `__env._11ty.functions.${name}`;
|
|
15
|
-
const ctx = '__env._11ty.ctx';
|
|
14
|
+
const fn = `__env.utils._11ty.functions.${name}`;
|
|
15
|
+
const ctx = '__env.utils._11ty.ctx';
|
|
16
16
|
let args = [code.replace(name, '').trim()];
|
|
17
17
|
|
|
18
18
|
const varname = output.startsWith('__shortcode_content')
|
package/src/modules/utils.js
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
//
|
|
2
|
-
const REQUIRED_API_METHODS = [
|
|
1
|
+
// Project-wide constants
|
|
2
|
+
export const REQUIRED_API_METHODS = [
|
|
3
3
|
['getShortcodes', 'v3.0.0-alpha.15'],
|
|
4
4
|
['getPairedShortcodes', 'v3.0.0-alpha.15'],
|
|
5
5
|
['getFilters', 'v3.0.0-alpha.15'],
|
|
6
6
|
['addExtension', 'v1.0.0'],
|
|
7
7
|
];
|
|
8
8
|
|
|
9
|
+
export const CONTEXT_DATA_KEYS = ['page', 'eleventy'];
|
|
10
|
+
|
|
11
|
+
// Project-wide helper functions
|
|
9
12
|
export function logError(message) {
|
|
10
13
|
console.error(`[eleventy-plugin-vento] ${message}`);
|
|
11
14
|
}
|