eleventy-plugin-vento 3.0.0 → 3.0.1
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 +12 -0
- package/package.json +4 -4
- package/src/engine.js +60 -61
- package/src/index.js +12 -12
- package/src/modules/create-vento-tag.js +2 -2
- package/src/modules/utils.js +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# eleventy-plugin-vento
|
|
2
2
|
|
|
3
|
+
## 3.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 9f5a90f: Various Refactors - These changes shouldn't have any observable effect on your templates or usage.
|
|
8
|
+
|
|
9
|
+
- 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.
|
|
10
|
+
|
|
11
|
+
- `DATA_KEYS` (used internally) moved into utils file alongside other utilities (like compatibility checks) and renamed to `CONTEXT_DATA_KEYS`.
|
|
12
|
+
|
|
13
|
+
- 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.
|
|
14
|
+
|
|
3
15
|
## 3.0.0
|
|
4
16
|
|
|
5
17
|
### 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.1",
|
|
4
4
|
"description": "Adds support for the Vento templating language to Eleventy.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@11ty/eleventy": "3.0.0-beta.1",
|
|
39
39
|
"@changesets/cli": "2.27.8",
|
|
40
|
-
"eslint": "9.11.
|
|
40
|
+
"eslint": "9.11.1",
|
|
41
41
|
"eslint-config-flat-gitignore": "0.3.0",
|
|
42
42
|
"eslint-config-prettier": "9.1.0",
|
|
43
43
|
"eslint-plugin-unicorn": "55.0.0",
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
"scripts": {
|
|
55
55
|
"test": "vitest --run",
|
|
56
56
|
"lint": "eslint '**/*.js'",
|
|
57
|
-
"ci:version": "changeset version && pnpm install --no-frozen-lockfile",
|
|
57
|
+
"ci:version": "npm audit signatures && 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,69 @@ 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?} key */
|
|
29
|
+
emptyCache(key) {
|
|
30
|
+
return key ? env.cache.delete(key) : env.cache.clear();
|
|
31
|
+
},
|
|
22
32
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
33
|
+
/** @param {import('ventojs/src/environment.js').Plugin[]} plugins */
|
|
34
|
+
loadPlugins(plugins) {
|
|
35
|
+
for (const plugin of plugins) {
|
|
36
|
+
env.use(plugin);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
29
39
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
/** @param {PageData} newContext */
|
|
41
|
+
loadContext(newContext) {
|
|
42
|
+
// Loop through allowed keys and load those into the context
|
|
43
|
+
for (const K of CONTEXT_DATA_KEYS) {
|
|
44
|
+
env.utils._11ty.ctx[K] = newContext[K];
|
|
45
|
+
}
|
|
46
|
+
},
|
|
34
47
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
48
|
+
/** @param {Record<string, EleventyFunction>} filters */
|
|
49
|
+
loadFilters(filters) {
|
|
50
|
+
for (const [name, fn] of Object.entries(filters)) {
|
|
51
|
+
env.filters[name] = (...args) => fn.apply(env.utils._11ty.ctx, args);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
41
54
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
55
|
+
/**
|
|
56
|
+
* @param {Record<string, EleventyFunction>} shortcodes
|
|
57
|
+
* @param {boolean} paired
|
|
58
|
+
*/
|
|
59
|
+
loadShortcodes(shortcodes, paired = false) {
|
|
60
|
+
for (const [name, fn] of Object.entries(shortcodes)) {
|
|
61
|
+
env.utils._11ty.functions[name] = fn;
|
|
62
|
+
env.tags.push(createVentoTag(name, paired));
|
|
63
|
+
}
|
|
64
|
+
},
|
|
49
65
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
66
|
+
/**
|
|
67
|
+
* @param {PageData} data
|
|
68
|
+
* @param {string} content
|
|
69
|
+
* @param {string} path
|
|
70
|
+
*/
|
|
71
|
+
async process(data, content, path) {
|
|
72
|
+
// Reload context
|
|
73
|
+
this.loadContext(data);
|
|
56
74
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
* @param {boolean} paired
|
|
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
|
-
}
|
|
75
|
+
// Process the templates
|
|
76
|
+
const result = await env.runString(content, data, path);
|
|
67
77
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
* @param {string} content
|
|
71
|
-
* @param {string} path
|
|
72
|
-
*/
|
|
73
|
-
async process(data, content, path) {
|
|
74
|
-
// Reload context
|
|
75
|
-
this.loadContext(data);
|
|
78
|
+
// Clear the cache for this path if the input doesn't match
|
|
79
|
+
if (data.page?.rawInput !== content) env.cache.clear(path);
|
|
76
80
|
|
|
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
|
-
}
|
|
81
|
+
return result.content;
|
|
82
|
+
},
|
|
83
|
+
};
|
|
85
84
|
}
|
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,17 @@ 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) => engine.process(data, inputContent, inputPath);
|
|
120
117
|
},
|
|
121
118
|
|
|
122
119
|
// Custom permalink compilation
|
|
123
120
|
compileOptions: {
|
|
124
121
|
permalink(linkContents) {
|
|
125
|
-
if (typeof linkContents !== 'string')
|
|
126
|
-
|
|
122
|
+
if (typeof linkContents !== 'string') {
|
|
123
|
+
return linkContents;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return async (data) => engine.process(data, linkContents);
|
|
127
127
|
},
|
|
128
128
|
},
|
|
129
129
|
});
|
|
@@ -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
|
}
|